When I ssh to a server and start a script that is supposed to run for several days, it stops executing some time after I log off. Why? I suppose the server runs 24/7.
And what does screen/tmux do to prevent this from happening?
From an operating system's point of view, every running program is a process. When the kernel is done initializing it will start one process, mostly
When a process exits in linux/unix, the kernel sends to all childprocesses the signal number 15 (SIGTERM). It can be caught by the process and the process should do whatever it has to do to exit in a save way. You may know also know the signal number 9 (SIGKILL). This signal cannot be caught by the process: the kernel exits the process by himself.
You can see that
In fact, this is what happens when you detach the
You need to use the nohup command. A explanation is provided here. Basically it detaches the program you are running from your terminal session it is closed the program does not die with its parent. tmux and screen also detach the programs they run that is why you get the same behavior.