System Call in Linux 

important library:

for writing and executing of these system calls unistd.h must be included before the main program otherwise this will not work properly or might to work.

Execvp()

This system call is used to execute the other process once the invoked program executed control will shift from the main program to the running one.

Syntax
int execvp (const char *file, char *const argv[]);


file: points to the file name associated with the file being executed.
argv:  is a null-terminated array of character pointers.


Programming Examples:
/*This example will explain to you how to write a simple program to execute it*/
anotherprocess.c
#include<stdlib.h>
#include<stdio.h>
#include<unistd.h>
int main(int argr,char *argv[])
{
   print("Hello I'm from another world ");
  return 0;
}

compile it using gcc:
 gcc anotherprocess.c -o anotherprocess
note: if you wouldn't get error then write the code below:
callingprog.c

#include<stdlib.h>
#include<stdio.h>
#include<unistd.h>
int main(int argr,char *argv[])
{
   print("Hello I'm from Calling function");
   char *args[]={"Hello world","ali",NULL};
  
   execv("./anotherprocess",args);
   prinf("if execv will not work i'll be printed ");
  return 0;
}
compile it using gcc:
 gcc callingprog.c -o callingprog
./callingprog
note: program will output the required results.



Submission for Execv() Command Task:




Post a Comment

Previous Post Next Post