How do I put an already-running process under nohup?
Using the Job Control of bash to send the process into the background:
- Ctrl+Z to stop (pause) the program and get back to the shell.
bg
to run it in the background.disown -h [job-spec]
where [job-spec] is the job number (like%1
for the first running job; find about your number with thejobs
command) so that the job isn't killed when the terminal closes.
Suppose for some reason Ctrl+Z is also not working, go to another terminal, find the process id (using ps
) and run:
kill -SIGSTOP PID kill -SIGCONT PID
SIGSTOP
will suspend the process and SIGCONT
will resume the process, in background. So now, closing both your terminals won't stop your process.
The command to separate a running job from the shell ( = makes it nohup) is disown
and a basic shell-command.
From bash-manpage (man bash):
disown [-ar] [-h] [jobspec ...]
Without options, each jobspec is removed from the table of active jobs. If the -h option is given, each jobspec is not removed from the table, but is marked so that SIGHUP is not sent to the job if the shell receives a SIGHUP. If no jobspec is present, and neither the -a nor the -r option is supplied, the current job is used. If no jobspec is supplied, the -a option means to remove or mark all jobs; the -r option without a jobspec argument restricts operation to running jobs. The return value is 0 unless a jobspec does not specify a valid job.
That means, that a simple
disown -a
will remove all jobs from the job-table and makes them nohup