操作系统的作业,不会做,谁能帮帮我啊
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int varA = 40;
int main(int argc, int **argv)
{
int varB = 29;
pid_t retFork=2;
fprintf(stderr, "PID: %4ld retFork:%2d varA: %2d varB: %2d\n", getpid(), retFork, varA, varB);
retFork = fork();
varA = 80;
fprintf(stderr, "PID: %4ld retFork:%2d varA: %2d varB: %2d\n", getpid(), retFork, varA, varB);
switch (retFork){
case -1:
fprintf(stderr, "The fork system call failed\n" );
fprintf(stderr, "PID: %4ld retFork: %2d\n", getpid(), retFork);
exit(1);
case 0:
varA += 10;
varB += 10;
fprintf(stderr, "PID: %4ld retFork: %2d\n", getpid(), retFork);
default:
fprintf(stderr, "PID: %4ld retFork: %2d\n", getpid(), retFork);
varA += 25;
varB += 25;
exit(1);
}
fprintf(stderr, "PID: %4ld varA: %2d varB: %2d\n", getpid(), varA, varB);
return 0;
}
程序在上面了,文件名叫createprocess.c,作业题目如下:
a. [4 points] 编译上述程序并运行它
i. 给出 parent process 和 the child process 的输出结果
ii. 观察变量retFork, varA and varB 的变化. 解释变量 retFork, varA 和 varB 的值变化的原因.
第二题不会翻译了,实在抱歉:
[4 points]Modify the createprocess.c program to have only the parent process voluntarily surrender the CPU for 2 seconds using the sleep system call. Compile and run the modified program.
i. Does the call to sleep function change the output produced by the two processes? Explain.
ii. Does the call to sleep function change the final value of the varA and varB variables in the two processes? Explain.
那位大虾可以给我详细的解释一下啊,这门课学的是在一头雾水。求正解!