Question: 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.

Answer: 
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 `mpirun`s, use:

```
$ pgrep -u `whoami` mpirun

```
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`](http://www.unix.com/man-page/opensolaris/1/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.