Unix system calls 2

Unix System Calls
(exec, exit, wait)

// Unix system calls
// exec, exit, wait
#include<stdio.h>
#include<string.h>
#include<sys/types.h>
#include<unistd.h>
int main(int argc, char *argv[])
{
pid_t pid;
int cstatus;
pid_t c;
pid=fork();
if(pid == -1)
printf(“\n Error in creating process “);
else if(pid == 0)
{
printf(“\nExecuting in child process”);
execvp(argv[1], &argv[1]);
perror(“exec failure”);
exit(1);
}
else
{
printf(“\nExecuting in parent process”);
c = wait(&cstatus); /* Wait for child to complete. */
printf(“\nParent: Child %ld exited with status = %d\n”, (long) c, cstatus);
}
}