Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I keep running a unix program in the background even if I log out?

Tags:

unix

I want to run a Perl script with some while(1) loop in the background on a unix machine until I kill it.

This is a remote computer to which I don't have administrative permissions (so for some reason, I can't use Daemon::Generic::While1), I log to it through SSH, and I want it to continue to run after I log out.

One way I found out is write something like this to bash:

nohup ./my_script.pl &

Is there some other, more preferable way to do it?

Editing the crontab is forbidden on that computer (while running background and long-lasting processes isn't).

like image 845
Karel Bílek Avatar asked Sep 29 '09 23:09

Karel Bílek


2 Answers

My preferred method, and arguably the easiest, is using screen:

screen -d -m ./myProcess
like image 193
Yuval Adam Avatar answered Oct 05 '22 22:10

Yuval Adam


You need to close stdout, stderr, stdin, otherwise you are still bound to that specific TTY

./my_script.pl >/dev/null 2>&1 </dev/null &

This should do the trick.

like image 27
user224579 Avatar answered Oct 05 '22 22:10

user224579