1.
bb.c
#include<stdio.h>
#include<sys/types.h>
#include<unistd.h>
int main(int argc,char ** argv){
pid_t pid;
pid=fork();
if(pid<0) // error
{
printf("there have something wrong\n");
}
if(pid>0) // father
{
printf("this is main process pid is %d\n", pid);
wait(NULL);
}
if(pid==0) // son
{
printf("this is new processs");
if( execl( "./aa","aa",NULL) < 0)
{
perror("execv error ");
}
sleep(20000);
}
return 0;
}
aa.c
#include <stdio.h>
main()
{
int pid;
printf("begin ...\n");
pid = fork();
if (pid == 0) {
printf("I am the child\n");
sleep(20000);
exit(0);
} else {
printf("the child process pid is %d\n", pid);
wait(NULL);
printf("child process has terminated. \n");
sleep(100);
}
}
1)请指出它们之间的关系,用pstree
2)请用ps命令显示各进程id,及父进程id(ppid)
3)请控制程序退出到僵尸状态