How do I keep a Perl script running on Unix after I log off?

流过昼夜 提交于 2019-12-04 20:08:49

This is just a guess, but something I've seen with some versions of ssh and nohup: if you've logged in with ssh then you may need to need to redirect stdout, stderr and stdin to avoid having the session hang when you exit. (One of those may still be attached to the terminal.) I would try:

nohup /path/to/./thescript.pl > whatever.stdout 2> whatever.stderr < /dev/null &

(This is no longer the case with my current versions of ssh and nohup - the latter redirects them if it detects that any is attached to a terminal - but you may be using different versions.)

Use screen. It creates a terminal which keeps going when you log out. When you log back in you can switch back to it.

Alex Reynolds

If you want to keep a process running after you log out:

disown -h <pid>

is a useful bash built-in. Unlike nohup, you can run disown on an already-running process.

First, stop your job with control-Z, get the pid from ps (or use echo $!), use bg to send it to the background, then use disown with the -h flag.

Don't forget to background your job or it will be killed when you logout.

Syntax for nohup looks ok, but your account may not allow for processes to run after logout. Also, try redirecting the stdout/stderr to a log file or /dev/null.

Zimbabao

Run your command in background.

/path/to/./thescript.pl &

To get lits of your background jobs

   jobs

Now you can selectively disown any of the above jobs, with its jobid.

disown <jobid>

All the disowned process should be keep on running even after you logged out.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!