- 论坛徽章:
- 0
|
用C写个程序 需要创造2个进程,其中第一个子进程应该创造2个进程,第二个子进程创造3个以上的进程.每个(5个当中)重孙进程(不是其他的进程或者子进程)应该写它的进程数,以及标准输出它双亲的进程数(用16进制表示)这个C程序应该不包含子程序或者"defines"(定义) 只仅仅要单一的输出状态(output statement)
请问下这个要怎么做啊, 我只会写一层结点的,但这个2层结点的还没搞明白有高手帮帮我吗.
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
main() {
int i,n;
pid_t child;
printf("How many processes do you want? \n");
scanf("%d",&n);
for (i=1; i<n; ++i)
if (child = fork()) break;
printf("This is process : %ld, with parent : %ld \n",
(long)getpid(), (long)getppid());
} |
|