Hi All,

 

I am using a wrapper program which runs “mpiexec –n 5 actual_program” using a popen command.

[ This is the simplified version of running my program. Ideally there is a TCL layer which does these things].

I have attached my program here.

 

My actual program has installed SIGINT signal handler and takes some action before it exits.

It also writes lot of information on stdout and a file.

 

In general, if I press CTRL+C, I expect SIGINT to be passed to all the underlying processes.

However, in my case, although the processes receive SIGINT, they are killed immediately.

 

I have noticed that If I run using

system(“mpiexec –n 5 actual_program”),  SIGINT is delivered and appropriate actions are taken.

 

I am a bit confused here. The only thing I can relate is that there is somehow a SIGPIPE signal which might lead mpiexec to kill all subprocesses.

Can someone please have a look and let me know what is the issue here and what can be a done.

 

Thanks,

Hirak

 

// wrapper program

 

#include <stdio.h>

#include <signal.h>

#include <string.h>

#include <stdlib.h>

 

 

 

int main ()

{

 

  const char* command = "mpiexec -n 5  ./mpiprog.out";

  #if 1

  FILE *fp = popen(command, "r");

  if (!fp) {

    printf ("failed\n");

  }

  while (!feof(fp)) {

    char ch ;

    fscanf(fp, "%c", &ch);

    printf ("%c", ch);

  }

 

  pclose(fp);

#else

  system (command);

#endif

}

 

//mpiprog.c

#include "mpi.h"

#include <signal.h>

#include <string.h>

#include <stdio.h>

#include <stdlib.h>

 

void signalHandler(int signum, siginfo_t *info, void *ptr)

{

  fprintf (stdout,"******** SIGINT *******************\n");

  MPI_Finalize();

  exit (0);

}

 

int main(int argc, char** argv)

{

  struct sigaction act;

  memset(&act, 0, sizeof(act));

  act.sa_sigaction = signalHandler;

  act.sa_flags = SA_SIGINFO;

  sigaction(SIGINT, &act, NULL);

 

  

  MPI_Init(&argc, &argv);

 

 

  while (1)

  {

 

    sleep (10);

    printf ("---Hhahaha\n");

  }

 

  MPI_Finalize();

}