Home > Net >  Kill with nohup process ID
Kill with nohup process ID

Time:04-27

Can I terminate a command run with nohup later? Or can I run the kill command with the process ID of nohup?

Can I get the process ID as a result of working with the nohup command? Although there is more than one nohup at the same time.

CodePudding user response:

You don't need nohup. It does exactly two things:

  • Any of stdin, stdout or stderr that are attached to the TTY get redirected (to /dev/null in the stdin case, or to nohup.out in the stdout and stderr cases).
  • HUP signals received by nohup are not propagated to the child.

The first is just the same as normal shell redirection (but with a hardcoded destination, which you normally don't want anyhow). The second achieves the same goal as using disown -h to tell the shell not to propagate a HUP to the targeted child (which is default behavior in the first place when your shell is noninteractive).

Thus, you can avoid needing nohup entirely, with something like:

yourcommand </dev/null >/dev/null 2>&1 & yourcommand_pid=$!
disown -h "$yourcommand_pid"

...which lets you later run kill "$yourcommand_pid".

  • Related