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

```
```
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`