Ubuntu下C、C++进程间的编程

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
pid_t pid;
int v = 0;

pid = fork();
if(pid < 0)
{
printf("Error.");
exit(-1);
}


if(0 == pid)
{
v++;
printf("id:%d, v=%d\n", getpid(), v);
}
else
{
v--;
printf("id:%d, v=%d\n", getppid(), v);
}


printf("v=%d\n", v);
return 0;
return 0;
}
posted @ 2014-04-16 11:18  ZhangAihua  阅读(352)  评论(0编辑  收藏  举报