as far i know nohup command still running when the user close the terminal, but not when the user logged out. Is it even possible? is all process will terminated when the user logged out?
2 Answers
Originally "logging out" was exactly the same thing on Unix as "closing the terminal". (Well, disconnecting the terminal or hanging up, because originally it was a physical device with a wired connection and only later became an X11 app.) Whenever you disconnected, the system would send SIGHUP to all remaining processes, and they would interpret it as an exit command... or they could just ignore it and carry on. On such systems, if the program ignored SIGHUP it would continue running after logout. (Hence the nohup
command, which tells the program to ignore SIGHUP.)
In current systems (primarily Linux), whether processes remain alive or not is completely separate from the terminal hangup, and can be implemented both ways:
Traditionally background processes are not touched during logout at all: if they survived the terminal closing, they won't even notice the subsequent logout. This is the case on non-systemd Linux as well as most BSDs.
In various systemd-using Linux distributions, however, all processes within the cgroup are killed during logout by default. This uses a different signal than terminal hangup (usually SIGTERM), so if this feature is active, it completely bypasses any nohup usage.
So in short, it's possible but it depends on your how your OS/distribution is configured.
If you have systemd as the init system, either disable the "KillUserProcesses=" option in /etc/systemd/logind.conf (reboot afterwards), or activate the "user service manager" using 'loginctl enable-linger' and use 'systemd-run --user' to start your background jobs.
-
Well, thanks, i just know that when i open new terminal it's like create new login session for user, so when i closed that terminal it's like i just logged out, or something like that. I just understand this line "Originally "logging out" was exactly the same thing on Unix as "closing the terminal".", the rest is still too hard for noob like me... Thank you...– ace cocCommented Jun 15, 2019 at 19:57
-
how about the complete system shutdown or
sudo reboot
for instance? willnohup
get killed in such scenarios?– doplanoCommented Jan 9, 2023 at 12:11
Absolutely a nohup’ed command can continue running when the user logs out
— that’s basically the primary purpose of nohup
.
-
Thank you, but, is there any post or source i can read for keep this nohup command running even my user logged out, because mine doesn't work. Running fedora 17 via virtual box, processing script myjob.sh #! /bin/bash while : do find / -print > testfile sort testfile –o testresult echo “End process on ‘date’” >> proses.log done run that script with "nohup ./myjob.sh" is there any mistake in my script or command?– ace cocCommented Jun 15, 2019 at 19:37
screen
will be much superior to using eithernohup
or&
.