SSH vs. nohup and hung jobs

Leeland's picture

Every 6 months or so I have some little loop I wrote to run a process on a long list of servers sit and hang forever by waiting for the nohup background process to end before moving on to the next host. Naturally I come back after getting lunch expecting all the boxes to be busily humming away to find 3 have finished and the 4th is still running. This of course causes me to remember that ssh hangs on processes even if they are pushed off to the background with a nohup. A while back I discovered this and after digging around I found that this is actually expected and correct (well correct for the standard) behavior. The problem is in the handling of stdin and stdout. This can be overcome by redirecting all the pipes to something NOT ssh.

ssh user@host 'nohup command </dev/null >/dev/null 2>&1 &'

Don't bother complaining about this. It is a known issue, but is not considered a bug according to the POSIX standard which ssh complies with. Essentially if a process is still attached to the tty ssh should not close the connection.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <em> <strong> <b> <i> <big> <small> <sub> <sup> <cite> <code> <ul> <ol> <li> <dl> <lh> <dt> <dd> <br> <p> <table> <th> <td> <tr> <pre> <blockquote> <h1> <h2> <h3> <h4> <h5> <h6> <hr>
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.