Is it possible to start the program from the terminal and continue to work after closing the terminal?

I wrote a program that I run after connecting to the box through SSH. It has some user interactions, such as selecting parameters after a request, and usually I wait for the processes that it completes to complete before leaving the system, which closes the terminal and terminates the program. But now the process is quite long, and I do not want to wait while you log in, so how can I implement a workaround for this in C, please?

+5
source share
6 answers

You can run the program in the background by running the &

wget -m www.google.com &

"screen", -

wget -m www.google.com

(PRESS CTRL + D)

screen -r (TO RE ATTACH)

http://linux.die.net/man/1/screen

+7

HUP- . , , , SIGHUP.

, nohup.

+2

. . , , , .

+1

- nohup (1):

nohup mycmd < /dev/null >& output.log &

, , /dev/null , , .

SIGHUP, . stdin/stdout/stderr, , ssh.

, , bash.

+1

:-) TIMTOWTDI... , ​​ dtach GNU screen.

- C, , , ...

0

C- :

//do interactive stuff...  
if(fork())
     exit(0);
//cool, I've been daemonized.

If you know that the code will never exit on a machine other than linux or BSD, you can even use daemon()

//interactive...
daemon(0, 0);
//background...
0
source

All Articles