POSIX/nohup

From Adam Meola - wiki
Jump to navigation Jump to search

Definition:

The command to ignore the HUP (hangup) signal.

It prevents the process from exiting when the terminal or ssh session is closed.

How to use it

Start a process

  • In the terminal:
    • cd to the directory you'd like to start the process in.
    • Run:
nohup [commandYoudLikeToKeepRunningAfterClosed] > /dev/null 2>&1 & echo $! > process.pid
  • This will start the process, and save a "process.pid" (process id number) file to the directory
  • This is so that your filesystem has a record of which process is running, for use later.

Stop a process

  • In the terminal:
    • cd to the directory that the applicable process was started in.
    • Run:
kill -9 `cat ./process.pid`
  • This will read the "process.pid" file, and use the value previously saved to kill that process.