这是创建子进程的代码的一部分。
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
main()
{
pid_t pid;pid_t被声明为pid.But值的变量与整数相同。
int x = 5;
pid = fork();fork()是创建子进程的函数。
x++;
if(pid<0)
{
printf("process creation error");
exit(-1);
}
else if(pid==0)
{
printf("Child Process");
printf("\nChild Process ID is %d",getpid());
x++;
printf("\nValue of X is %d",x);
printf("\nProcess id of parent is %d",getppid());
}发布于 2015-01-19 21:42:56
https://stackoverflow.com/questions/28033916
复制相似问题