本帖最后由 西乡新丰客 于 2017-1-10 19:55 编辑
请问各位:我想看一个并行程序的进程关系,就试了一个小程序。如下
#include <stdio.h>
#include "mpi.h"
#include <unistd.h>
int main(int argc, char* argv[])
{
int myid,numprocs;
int namelen;
char processor_name[MPI_MAX_PROCESSOR_NAME];
pid_t fpid;
int count=0;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD,&myid);
MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
MPI_Get_processor_name(processor_name,&namelen);
printf("hi!process %d of %d on %s*******child %d , parent %d \n",myid,numprocs,processor_name,getpid(),getppid());
MPI_Finalize();
fpid=fork();
if (fpid < 0)
printf("error");
else if (fpid == 0)
{printf("child,%d,parent,%d\n",getpid(),getppid());
count++;}
else
{printf("parent,%d,grandparent,%d\n",getpid(),getppid());
count++;}
printf("count %d\n",count);
return 0;
}
然后编译,并行运行得出其结果(比如-np 3):
hi!process 1 of 3 on liqizhi-YangTianT4900c-00*******child 3301 , parent 3295
hi!process 2 of 3 on liqizhi-YangTianT4900c-00*******child 3302 , parent 3295
hi!process 0 of 3 on liqizhi-YangTianT4900c-00*******child 3300 , parent 3295
parent,3301,grandparent,3295
count 1
child,3309,parent,3301
count 1
parent,3302,grandparent,3295
count 1
parent,3300,grandparent,3295
count 1
child,3311,parent,1525
child,3310,parent,1525
count 1
count 1
其中这个1525是怎么来的?而且少了3203进程。有时会运行正常,有时就会出现这个1525进程。
查看其进程如下:
PID TTY STAT TIME COMMAND
1525 ? Ss 0:00 /sbin/upstart --user
这是为什么
|