'Kill with nohup process ID
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.
Solution 1:[1]
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/nullin the stdin case, or tonohup.outin 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".
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
