Background process after logout
Some times we need leave a process running after logout. But, how we can do this?
Let's imagine we have an application like hello. The hello app show the string "Hello World!" and stuck execution. The source code is showed down:
#include <stdio.h> main(){ printf("Hello World!"); while(1); }
There are actually 2 ways of doing this, using nohup and using screen
nohup
Nohup is useful for applications which don't need any input in stdin. This might be useful for EggDrop bot or ZNC. It's not useful in case of such programs as irssi, because irssi is rather useless without input (of course correctly configured irssi will still able to connect into server, but you will not able to interact with it).
Well, this application will run forever, at least until it will be killed or closed by function in code (Warning: and use 100% CPU, so don't try on SHellium). How we can execute this application and logout after without their close? Simple! Just try this command:
$ nohup ./hello &
After the enter key press the file "nohup.log" will be created and all stdout will be sent to that file. If you check the "nohup.log" file (with cat command) you will see "Hello World".
You can now do the exit command and the application will continue running as a background process.
screen
More details are available at screen page.
It's also possible to use screen to do this effect. Unlike nohup, it also allows to detach processes, and after you will back, to attach them again. This makes this more useful for programs which need input. And you can easily run in screen programs which doesn't need input, but this is rather useless.
Application, just like in case of nohup, will work until it will send exit signal. First you have to type.
$ screenIf you want to log processes (WARNING: don't do this with programs with very complicated interface, where screen commonly refreshes, such as in irssi, unless you want to get very big log files) you can use -L, if you want Unicode use -U.
When you will want do end, just press CTRL+A, and after pressing it press D (not CTRL+D). It should display [detached] and back to your main shell. If you will want to go back into program type.
$ screen -r