0

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?

1
  • Note that in most cases where you want to start a long-lived background process manually, running it under screen will be much superior to using either nohup or &. Commented Jun 15, 2019 at 20:06

2 Answers 2

2

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.

2
  • 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 coc
    Commented Jun 15, 2019 at 19:57
  • how about the complete system shutdown or sudo reboot for instance? will nohup get killed in such scenarios?
    – doplano
    Commented Jan 9, 2023 at 12:11
0

Absolutely a nohup’ed command can continue running when the user logs out — that’s basically the primary purpose of nohup.

1
  • 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 coc
    Commented Jun 15, 2019 at 19:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .