I have started a Perl script from the terminal that runs in the background:
>perl myScript.pl &
If I logout, will it stop my script from running?
Ask Different is a question and answer site for power users of Apple hardware and software. It only takes a minute to sign up.Sign up to join this community
Yes, this is dead easy to test. Write a perl script that appends the date to a file every minute, and run it in the background. Log out, wait 5 minutes, log in, check for 5 entries corresponding to the times you are logged out. To get it working in future (too late if it's already running) use nohup as explained in another answer. You can background a foreground script after you start it (CTRL-Z) but you can only nohup it at execution
In addition to @stuffe's answer, if you are logged in via
ssh and run your command, it will die when you close the connection. So, if you were at home and
ssh'ed into your office workstation and executed your
perl myScript.pl & command, it would die when you
exit'ed from the
To avoid this problem, you'll want to use the
nohup command, which dates back to the teletype days and stands for "no hangup" --- essentially it causes the command to ignore the POSIX HUP (hangup) signal. It is used as:
nohup perl myScript.pl &
This will keep running on your office workstation even after you have disconnected/logged out from your home machine.