Commit bbe15365 authored by Zhaozhong Liu's avatar Zhaozhong Liu
Browse files

Prelab 1.3 completed

parent 53f485f9
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
int main()
{
pid_t pid,pid1,pid2;
pid1 = fork();
pid2 = fork();
int countP = 1;
int count1 = 1;
int count2 = 1;
int i = 0;
//for (i = 0; i<100; i++){
for (;;){
if (pid1 == -1 || pid2 == -1){
perror("cannot fork");
return -1;
}
else if(pid1 ==0){
//printf("This is child process1\n");
printf("Child1: %d\n", count1);
count1 ++;
}
else if(pid2 ==0){
//printf("This is child process2\n");
printf("Child2: %d\n", count2);
count2 ++;
}
else {
//printf("This is parent process\n");
printf("Parent: %d\n", countP);
countP ++;
}
}
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment