|
楼主 |
发表于 2006-7-13 08:32:38
|
显示全部楼层
还有一个问题:
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
void h_exit(int status)
{
if (WIFEXITED(status))
printf("normal termination ,exit status=%d \n",WEXITSTATUS(status));
else if (WIFSIGNALED(status))
printf("abnormal termination,signal number=%d %s \n",WTERMSIG(status));
}
//主函数。示范三种结束进程的不同的方式,并调用 h_exit 过程处理返回状态字
int main(void)
{
pid_t pid;
int status;
//子进程正常退出
if((pid=fork())<0)
{
printf("error");
exit(0);
}
else if (pid==0) //子进程
exit(7);
if (wait(&status)!=pid) //等待子进程
{
printf("wait error");
exit(0);
}
h_exit(status); //打印状态
//子进程终止
if ((pid=fork())<0)
{
printf("fork error");
exit(0);
}
else if (pid==0) //子进程
abort(); //产生信号 SIGABRT 终止进程
if(wait(&status)!=pid) //等待子进程
{
printf("wait error");
exit(0);
}
h_exit(status);////打印状态
//子进程除零终止
if((pid=fork())<0)
{
printf("fork error");
exit(0);
}
else if (pid==0) //子进程
status /=0; //产生信号 SIGFPE终止进程
if(wait(&status)!=pid) //等待子进程
{
printf("wait error");
exit(0);
}
h_exit(status);////打印状态
exit(0);
}
问题1:
大哥:
当程序执
else if (pid==0) //子进程
exit(7);
是不是子进程就退出去了
问题2:
后面的
if (wait(&status)!=pid) //等待子进程
{
printf("wait error");
exit(0);
}
是不是父进程执行的?
问题3:
还有
if (wait(&status)!=pid)
不明白意思?
问题4:
h_exit(status); //打印状态
是父进程执行的,还是子进程执行的?
问题5:
if ((pid=fork())<0)
{
printf("fork error");
exit(0);
}
是不是产生一个新的子进程?
谢谢! |
|