[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: && operator prevents backgrounding over ssh

From: Chet Ramey
Subject: Re: && operator prevents backgrounding over ssh
Date: Thu, 26 Sep 2013 16:25:59 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.0

On 9/26/13 11:44 AM, Geir Hauge wrote:
> 2013/9/26 Hinrik Örn Sigurðsson <address@hidden>
>> The "&&" operator in bash seems to inhibit backgrounding when run over
>> ssh. You can try it with the following:
>>   ssh localhost "cd /tmp && nohup sleep 10 >/dev/null 2>&1 &"
>> The above command will wait for sleep(1) to finish before returning.
>> If it is run without ssh, it returns immediately. Furthermore, other
>> shells such as dash and zsh will return immediately regardless of
>> whether ssh is used.
> Probably because it's equivalent to
>   { cd /tmp && nohup sleep 10 >/dev/null 2>&1; } &

This is correct.  The shell started in the background to run the compound
command also has to stick around to report the exit status back to its
parent, so it will exit when the sleep exits.

Maybe zsh and dash have optimized this case, since the exit status of
nohup/sleep will be the exit status of the backgrounded shell, but bash
has not.

> so the backgrounded process still have stdout and stderr connected to ssh.


> This should do what you want:
>   cd /tmp && { nohup sleep 10 >/dev/null 2>&2 & }

This will do the same thing and might be simpler:

cd /tmp && exec nohup sleep 10 >/dev/null 2>&1 &

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]