delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2011/07/06/15:12:39

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,T_TO_NO_BRKTS_FREEMAIL
X-Spam-Check-By: sourceware.org
MIME-Version: 1.0
In-Reply-To: <iv25no$u76$1@dough.gmane.org>
References: <iv25no$u76$1 AT dough DOT gmane DOT org>
Date: Wed, 6 Jul 2011 20:12:12 +0100
Message-ID: <CAHWeT-YB1RV+zXtM1+EnNvKVyymsj9BqYHrGe2nEPM25oL+Ypw@mail.gmail.com>
Subject: Re: Unable to disown process
From: Andy Koppe <andy DOT koppe AT gmail DOT com>
To: cygwin AT cygwin DOT com
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id p66JCWot001326

On 6 July 2011 18:24, Andrew DeFaria wrote:
> I have the following script that I use to tunnel nntp traffic:
>
>   #!/bin/bash
>   nohup ssh -NL 1119:news.mozilla.org:119 \
>         -L 2119:news.gmane.org:119 \
>         -L 3119:nntp.perl.org:119 \
>      andrew AT defaria DOT com > /dev/null 2>&1 &
>
>   disown
>
> If I run this script it works fine and I'm tunneled. The problem is I cannot
> exit the terminal in which I invoked this script. When I attempt to do this
> the terminal hangs. I can close the terminal (mintty BTW) forcefully and the
> ssh session remains but it was my understanding that disown should allow you
> to exit the current shell with the backgrounded/disowned process continuing
> to run. In fact I tested this on RHEL and it worked as expected. What's up
> with Cygwin?

Mintty stays open as long as any processes are connected to it, i.e.
until it gets an EOF from its underlying pseudo terminal device,
whereas other terminals quit as soon as their direct child process
finishes. The Cygwin console behaves the same as mintty in this regard
though.

Nohup doesn't disassociate a process from its terminal, it just blocks
the SIGHUP signal for indicating when the terminal is gone. And
'disown' removes a job from the shell's job table, but again, the
job's processes will remain connected to the terminal.

You can use the 'setsid' utility from the util-linux package to invoke
a program in its own session, i.e. without connection to the terminal
it is invoked from. For example:

setsid ssh -NL 1119:news.mozilla.org:119 \
         -L 2119:news.gmane.org:119 \
         -L 3119:nntp.perl.org:119 \
         andrew AT defaria DOT com

No need for 'nohup', redirections, backgrounding, or 'disown' with this.

Andy

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019