search by tags

for the user

adventures into the land of the command line

job control - long running processes

Have you ever started a long running process that you can’t just ctrl+c from before realising you should have started it in screen or tmux? Did you then want to go home from work but were not sure how much longer this process is gonna run for?

It’s pretty stupid, but if you really need to do it, this is how you save yourself.

Some long running process example:

$ htop

Press ctrl+z to pause the job

[1]+  Stopped                 htop

Push the job to the background

$ bg
[1]+ htop &

At this point the job is still tied to your shell session, and so if you log out, the job will still stop, so you need to disassociate your user with the process:

$ disown -h htop

Then log out. You might want to also be logged in on a second terminal with a different user to check the process is still running:

$ ps -ef | grep [h]top
root      4979  4964  0 09:27 pts/0    00:00:00 htop

Once the job has been disowned, there’s no way to re-own in or adopt it. If you want to stop it before it finishes on its own you must kill it.

$ kill -9 4979

I honestly wouldn’t recommend doing this, it’s literally the worst. But it’s good to know, there’s always (not always) a way out.