Search This Blog

How to use fork and exec System Call

Using fork and exec System calls in Linux (UNIX) operating systems. Fork system call is used to create a child process from a parent process.
#include<stdio.h>
main()
{

int pid;
pid=fork();
printf("%d\n",pid);
if(pid==0)
{
exec("/bin/date\n",NULL,NULL);
exit(0); }
else
{
printf("Parent process %d\n",pid); }}
if(sp)
while(dd=readdir(sp))
printf("--> %s\n",dd->d_name);
}
}

No comments: