I have started a program in parallel using the command:

    nohup mpirun -7 mylongprogram.py &

I now want to terminate the program. When I want to kill the process by the command:

    kill -9 <PID>

I see that another process with a different PID is started. How do I kill the entire mpi program and prevent nohup from doing this?

  • 1
    Questions about usage of general Unix tools like nohup should be asked on the Super User site.
    – Hristo Iliev
    Oct 21 '13 at 8:45
  • "prevent nohup from doing this". From doing what ?
    – Slyx
    Dec 29 '15 at 9:52

The command I usually do this is to use:

killall -u [USER]
  • Or, if you feel daring, kill -15 -1 as your non-root mpi-user (which logs you out, too).
    – Ned64
    Mar 28 '18 at 19:53

Instead of forcing the program to shut down from the outside, I'd try triggering a clean exit from inside. For example, create a file somewhere that the program periodically checks if it exists, and shuts itself down if it does (related reading: https://stackoverflow.com/questions/5433697/terminating-all-processes-with-mpi).


killall mpirun

or more specifically for your case :

ps -ef | grep mpirun | grep mylongprogram | awk '{print $2}' | while read p; do kill -9 $p ; done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.