标签:tpi IT学习 orm std The waitpid main tst ima
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
main()
{
int status;
pid_t pc,pr;
pc=fork();
if(pc<0) /* 如果出错 */
printf("error ocurred!\n");
else if(pc==0){ /* 子进程 */
printf("This is child process with pid of %d.\n",getpid());
}
else{ /* 父进程 */
pr=wait(&status);
if(WIFEXITED(status)){ /* 如果WIFEXITED返回非零值 */
printf("the child process %d exit normally.\n",pr);
}else /* 如果WIFEXITED返回零 */
printf("the child process %d exit abnormally.\n",pr);
}
}
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
main()
{
int status;
pid_t pc,pr;
pc=fork();
if(pc<0) /* 如果出错 */
{printf("error ocurred!\n");
return -1;}
else if(pc==0){ /* 子进程 */
printf("This is child process with pid of %d.\n",getpid());
}
else{ /* 父进程 */
pr=wait(&status);
if(WIFEXITED(status)){ /* 如果WIFEXITED返回非零值 */
printf("the child process %d exit normally.\n",pr);
printf("the return code is %d.\n",WEXITSTATUS(status));
}else /* 如果WIFEXITED返回零 */
printf("the child process %d exit abnormally.\n",pr);
}
}
标签:tpi IT学习 orm std The waitpid main tst ima
原文地址:https://www.cnblogs.com/banpingcu/p/11830647.html