FORK

 

// FORK

#include<stdio.h>

#include<stdlid.h>

#include<unistd.h>

#include<sys/types.h>

#include<sys/wait.h>

int main()      

{ pid_t pid;

pid = fork();      

if (pid < 0)

{ perror("Fork failed");

exit(EXIT_FAILURE); }

else if (pid == 0) {

printf("Child process: PID = %d\n", getpid());

execlp("/bin/ls", "ls", "-l", NULL);

perror("exec failed");

exit(EXIT_FAILURE);    }

else {

printf("Parent process: PID = %d,

            waiting for child...\n", getpid());

wait(NULL);

printf("Child process finished.\n"); }

return 0; }

Comments

Popular posts from this blog

FCFS Static code