Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I ran this command to try and get my python program to run in the background and let me exit the SSH connection I am using:

nohup python files.py >> files.log &

I then check ps to check it worked

$ ps a
  PID TTY      STAT   TIME COMMAND
13059 pts/0    Ss     0:00 -bash
13327 pts/0    R+     0:00 ps a
[1]+  Exit 1                  nohup python files.py >> files.log

What does this [1]+ Exit 1 mean?

And how can I run my program in the background letting me exit correctly?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

When you use the & at the end of a command in bash, it runs the command in the background. The [1]+ Exit 1 means that job 1 exited with status 1. The number between the [] is the job number, and the number after Exit is the exit status. If no exit status is shown, it means the command exited with status 0.

The reason you dont see this until you run another command is because by default the status of a completed backgrounded command is not shown until the prompt is updated. This means after another command exits, or you simply press <ENTER> on an empty prompt.

Edited:
You also do not need to use the nohup. Bash will only HUP a process when the shell itself receives a HUP. This doesn't happen if you exit cleanly (via exit, or CTRL+D).
However you can also use the disown builtin to make it so specific jobs don't get a HUP.
Lastly you can also set a SIGHUP handler to disown all jobs when the shell gets a HUP by doing function sighup { disown -a; exit 0; }; trap sighup HUP.

share|improve this answer
2  
No nohup is not for use when the shell doesn't have a & operator, it is to immune a process to the HUP signal sent when their parent shell or session leader terminates. –  Stéphane Chazelas Mar 25 '13 at 21:15
    
@StephaneChazelas Please see man 1 nohup, it specifically mentions this. & is quite capable of not HUPing backgrounded jobs. –  Patrick Mar 25 '13 at 21:23
    
My man page doesn't. Maybe you're referring to the GNU or BSD nohup man page comment saying that some shells (like (t)csh) have a builtin nohup command that would supersede it. –  Stéphane Chazelas Mar 25 '13 at 21:30
1  
It's not needed for bash, which can disown the job via the disown builtin. –  jordanm Mar 25 '13 at 21:35
1  
@ACarter no, the exit 1 generally means abormal termination. Programs which exit properly normally exit with status 0. Though the script can really do whatever it wants. –  Patrick Mar 26 '13 at 3:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.