Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to run a program from terminal and have it continue to run after you close the terminal?

Tags:

c

linux

I have written a program which I run after connecting to the box over SSH. It has some user interaction such as selecting options after being prompted, and usually I wait for the processes it carries out to finish before logging out which closes the terminal and ends the program. But now the process is quite lengthy and I don't want to wait whilst being logged in, so how could I implement a workaround for this in C please?

like image 959
user1166981 Avatar asked Jan 27 '12 16:01

user1166981


2 Answers

You can run a program in the background by following the command with "&"

wget -m www.google.com &

Or, you could use the "screen" program, that allows you to attach-deattach sessions

screen wget -m www.google.com

(PRESS CTRL+D)

screen -r (TO RE ATTACH)

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

like image 166
Seidr Avatar answered Nov 15 '22 10:11

Seidr


The process is sent the HUP signal when the shell exits. All you have to do is install a signal handler that ignores SIGHUP.

Or just run the program using nohup.

like image 22
Joni Avatar answered Nov 15 '22 10:11

Joni