Open MPI logo

Open MPI User's Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Open MPI User's mailing list

Subject: [OMPI users] function fgets hangs a mpi program when it is used ompi-ps command
From: Matheus Bersot Siqueira Barros (matheusbersotsb_at_[hidden])
Date: 2010-09-17 15:13:24

Open MPI Version = 1.4.2
OS = Ubuntu 10.04 LTS and CentOS 5.3

When I run the mpi program below in the terminal, the function fgets hangs.
How do I know it? I do a printf before and later the call of fgets and only
the message "before fgets()" is showed.

However, when I run the same program at Eclipse 3.6 with CDT or using gdb it runs normally.
If you change the command in the function popen to another one(for
instance: "ls -l"), it will run correctly.

I use the following commands to compile and run the program:

compile : mpicc teste.c -o

run : mpirun -np 4 ./

Does anyone know why the program behaves like that?

Thanks in advance,

Matheus Bersot.


#include <stdio.h>
#include "mpi.h"

int main(int argc, char *argv[])
   int rank, nprocs;
   FILE * pFile = NULL;
   char mystring [100];


   if(rank == 0)
   pFile = popen ("ompi-ps" , "r");
   if (pFile == NULL) perror ("Error opening file");
   else {
       printf("before fgets()\n");
       fgets (mystring , 100 , pFile);
       printf("after fgets()\n");
       puts (mystring);
     pclose (pFile);

   return 0;