Fork System Call in Linux
Write a C program to do the following when executed on a Linux system.
1. The parent process creates two other processes (child processes).
2. The parent prints "PARENT"
3. One child prints "CHILD 1"
4. The other child prints "CHILD 2"
C Code:
#include <stdio.h>
#include <unistd.h>
int main()
{
if (fork())
{
printf("parent\n");
if(fork()==0)
{
printf("child1\n");
}
}
else
{
printf("child2\n");
}
return 0;
}
Comments
Post a Comment