While you need a course of to proceed working even after you log out a Linux system, you’ve got a pair choices.
Certainly one of them is to make use of the disown command. It tells your shell to chorus from sending a HUP (hangup) sign to the method while you log out. So, the method continues working. This may be very helpful everytime you begin a course of after which, for some purpose, you may’t keep logged in and wait till it finishes.
The disown command is a shell built-in. Which means that you don’t have to put in it to make use of it, however it additionally signifies that it gained’t be obtainable in case you use a shell that doesn’t help it. For these of us utilizing bash and associated shells (zsh, ksh and so forth.), disown ought to be obtainable and you may confirm this with a command like this that lists shell built-ins after which appears for “disown”:
$ show_builtins | grep disown disown [-h] [-ar] [jobspec ... | pid > test [expr]
In contrast to nohup which has just about the identical impact, disown is used after you’ve began a course of. Simply specify the method ID with the disown command:
$ ps -ef | grep long-loop shs 799217 1 0 11:04 ? 00:00:00 /bin/bash /residence/shs/bin/bigjob $ disown 799217
The method will proceed working after you log out and, if it hasn’t completed by the point you log in once more, will nonetheless be working till it’s accomplished. In reality, it gained’t even be affected while you log out once more as a result of it won’t be related along with your present shell.
Take a look at disown
In case you’d wish to see how disown works, you may arrange a easy loop in a script. Right here’s an instance:
#!/bin/bash whereas true do date >> my.log sleep 600 finished
This script provides the present date and time to a file named “my.log” each 10 minutes and has no stopping level. You can begin it within the normal manner:
$ ./my-loop
Then, while you’re able to log out you may possibly run off someplace, droop your course of with ^z (maintain management key and press “z”). After that, checklist your processes:
$ ps PID TTY TIME CMD 801593 pts/3 00:00:00 bash 801812 pts/3 00:00:00 long-loop 801816 pts/3 00:00:00 sleep
Then use the disown command with the script’s course of ID:
$ disown 801812
Be aware that, in case you run your course of within the background from the beginning (e.g., my-loop &), you don’t want to make use of the ^z.
Terminating a disowned course of
Most processes won’t, after all, be designed to run eternally. They’ll most likely end earlier than you log again in once more. Within the case of this instance loop, you’d ultimately want to make use of a little bit of power to cease it when you’ve logged off and again on. The “certain kill” -9 choice ought to do that for you.
$ kill 801812 $ ps PID TTY TIME CMD 801593 pts/3 00:00:00 bash 801812 pts/3 00:00:00 long-loop <== Oops! Nonetheless working 801816 pts/3 00:00:00 sleep 802115 pts/3 00:00:00 ps $ kill -9 801812 <== certain kill $ ps PID TTY TIME CMD 801593 pts/3 00:00:00 bash 802150 pts/3 00:00:00 ps
Some choices
You might need observed within the output of the show_builtins command above that the disown command has a number of choices. The -a choice will disown all backgrounded processes whereas -r means it is going to solely disown working (not stopped) processes. In each instances, the roles being disowned will not present up while you sort “jobs”. While you use the -h choice, alternatively, the job won’t faraway from the roles checklist, although the shell will nonetheless chorus from sending an HUP sign to it while you sign off.
See the best way to use Ranger
Copyright © 2020 IDG Communications, Inc.
Leave a Reply