gaj
gaj

Reputation: 327

Finding pid of the mpirun command

After I issue a mpirun command, I want to get the pid of this process, so that I can kill this process later. How to do this without having to add '&' at the end of the mpirun command to send it to background?

Other condition is that there could be more than one mpirun processes running on the machine.

Upvotes: 2

Views: 2350

Answers (4)

Hristo Iliev
Hristo Iliev

Reputation: 74365

With Open MPI one could instruct mpirun to output its own PID by giving it the --report-pid option:

  • --report-pid - outputs the PID to the standard output;
  • --report-pid + outputs the PID to the standard error;
  • --report-pid /path/to/filename writes the PID into filename.

To get the PIDs of all your running mpiruns, use:

$ pgrep -u `whoami` mpirun

Upvotes: 3

tigerjack
tigerjack

Reputation: 1178

ps aux | grep application_name

This syntax works great on Ubuntu, but I don't know if it works well for the other distributions. It returns (at least) two different rows: one containing the pid of your current search process and the other containing the pid of the process you are searching for. The program PID is just the second column of the list.

You can run man ps or ps --help to see the manual of the ps command.

To kill a process check the options of the commands pkill kill and killall

Upvotes: 0

damienfrancois
damienfrancois

Reputation: 59070

Besides putting the & and using $! and then % to put the mpirun process bash to foreground:

$ mpirun -np 4 ./a.out &
[1] 12345
$ PID=$!
$ %
...

You can use the pkill commands to terminate it e.g. pkill mpirun but then you need to make sure only to have one mpirun process running, or you can write your MPI program so that it writes it PID to a file and then read this file, like many UNIX daemon do.

Upvotes: 0

Madh
Madh

Reputation: 131

You can use 'ps' to get pid

ps -A | grep process-name

Upvotes: 0

Related Questions