CS计算机代考程序代写 #include

#include
#include
#include
#include
#include

#define MAX_COUNT 3

void Code1(void); /* Code1 function declaration */
void Code2(void); /* Code2 function declaration */

int main()
{

pid_t ret_val1;

ret_val1 = fork();

if (ret_val1 < 0) { printf("Error in fork\n"); exit(1); } else if (ret_val1 == 0) { Code1(); } else if (ret_val1 > 0) {
Code2();
Code2();
}
return (0);
}

void Code1() {
int i;
pid_t pid;

pid = getpid();

for (i = 1; i <= MAX_COUNT; i++){ printf ("This line is from Code1 process, value = %d, pid = %d\n", i, pid); } printf("\n***Code1 function, pid %i is done***\n\n", pid); } void Code2() { int i; pid_t pid; pid_t ret_val2; ret_val2 = fork(); if (ret_val2 < 0) { printf("Error in fork\n"); exit(1); } else if (ret_val2 == 0) { pid = getpid(); for(i=1; i <= MAX_COUNT; i++) { printf("This line is from Code2 process, value = %d, pid = %d\n", i, pid); } printf("\n ***Code1 function, pid %i is done***\n\n", pid); } else { pid = getpid(); printf("\n***Code2 function, pid %i is done***\n\n", pid); } }