X-Recipient: archive-cygwin@delorie.com
X-Spam-Check-By: sourceware.org
Message-ID: <2ce9650b0811140323h2e620979w77118815bed87fdd@mail.gmail.com>
Date: Fri, 14 Nov 2008 11:23:28 +0000
From: "Chris January" <chris@atomice.net>
To: cygwin@cygwin.com
Subject: Re: Kill cygwin process form task manager
In-Reply-To: <448067AB8643614285E9B1DC376F273C0241F883@bermail.de.aastra.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
References: <448067AB8643614285E9B1DC376F273C0241F883@bermail.de.aastra.com>
X-Google-Sender-Auth: f178cffc2d92893f
X-IsSubscribed: yes
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
Precedence: bulk
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie.com@cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com

On Nov 14, 2008 10:20am, Michael Wiedmann wrote:
> I need hints how to act if someone kills my Cygwin (parent) process using Windows task manager and I want to kill all forked child processes.
>
> I already keep a list of all childs pids and can kill them successfully in an SIGINT handler (if the programm is started in foreground and is interrupted e.g. by Ctrl-C).

Untested on Cygwin, but works on Linux, etc.:
1. Create an anonymous pipe using the pipe function.
2. Fork the child.
3. Close the read fd in the parent and the write fd in the child.
4. Have child select on the read fd.
5. When the parent dies the select will return.
6. Try to read from the pipe. If read returns 0, i.e. end-of-file the
parent is dead.

Alternatively, do it the other way round, with the child occasionally
writing to the pipe and the parent draining it. The child will get
SIGPIPE when the parent dies.

Chris

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

