You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
650 B
38 lines
650 B
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
int main(int argc, char const *argv[])
|
|
{
|
|
int p1=fork();
|
|
if (p1==0)
|
|
{
|
|
/* code */
|
|
for (int i = 0; i < 2; ++i)
|
|
{
|
|
/* code */
|
|
printf("child: %d\n",getpid());
|
|
}
|
|
}else if(p1>0){
|
|
int p2=fork();
|
|
if(p2==0){
|
|
for (int i = 0; i < 3; ++i)
|
|
{
|
|
/* code */
|
|
printf("child: %d\n",getpid());
|
|
}
|
|
}else if(p2>0){
|
|
for (int i = 0; i < 4; ++i)
|
|
{
|
|
/* code */
|
|
printf("parent: %d\n",getpid());
|
|
}
|
|
}else{
|
|
printf("Failed to create p2.\n");
|
|
exit(1);
|
|
}
|
|
}else{
|
|
printf("Failed to create p1.\n");
|
|
exit(1);
|
|
}
|
|
return 0;
|
|
} |