Received: by 10.204.129.9 with SMTP id m9mr361393bks.1.1348749698474; Thu, 27 Sep 2012 05:41:38 -0700 (PDT) X-BeenThere: erlang-programming@googlegroups.com Received: by 10.204.7.203 with SMTP id e11ls3162203bke.8.gmail; Thu, 27 Sep 2012 05:41:38 -0700 (PDT) Received: by 10.204.4.211 with SMTP id 19mr359934bks.5.1348749698026; Thu, 27 Sep 2012 05:41:38 -0700 (PDT) Received: by 10.204.4.211 with SMTP id 19mr359931bks.5.1348749697998; Thu, 27 Sep 2012 05:41:37 -0700 (PDT) Return-Path: Received: from hades.cslab.ericsson.net (hades.cslab.ericsson.net. [192.121.151.104]) by gmr-mx.google.com with ESMTP id 27si549637bks.3.2012.09.27.05.41.37; Thu, 27 Sep 2012 05:41:37 -0700 (PDT) Received-SPF: pass (google.com: domain of erlang-questions-boun...@erlang.org designates 192.121.151.104 as permitted sender) client-ip=192.121.151.104; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of erlang-questions-boun...@erlang.org designates 192.121.151.104 as permitted sender) smtp.mail=erlang-questions-boun...@erlang.org; dkim=neutral (body hash did not verify) header...@gmail.com Received: from hades.cslab.ericsson.net (hades [192.121.151.104]) by hades.cslab.ericsson.net (Postfix) with ESMTP id 97DDD5C122; Thu, 27 Sep 2012 14:41:32 +0200 (CEST) X-Original-To: erlang-questi...@erlang.org Delivered-To: erlang-questi...@erlang.org Received: from mail-pa0-f53.google.com (mail-pa0-f53.google.com [209.85.220.53]) by hades.cslab.ericsson.net (Postfix) with ESMTP id 249975C002 for ; Thu, 27 Sep 2012 14:41:29 +0200 (CEST) Received: by padbj3 with SMTP id bj3so1547277pad.40 for ; Thu, 27 Sep 2012 05:41:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:mime-version:content-type:from:in-reply-to:date:cc :message-id:references:to:x-mailer; bh=/LaUuNtiX3tIznp5fZgQ1j+Ez0iSPsHSBv/jwEc5BmM=; b=CFbScd6Bsxgm4N7760d91km+ArTxV9lQ285njVtT7VgPC5nys+8y5iKbljMsTJRR/X WCkUiB8SMPQLBItT710S1xGlEBTHqii1n2ybjNOkenH1VAvy/6FPEX/62EMYjYKMa0VX ImuUAOreAkPxM6fTAPId6c4djmxvENKQZdwH6njzUqS1oowaPqrjCl487AuciYehpTIs JCgZasJ8CxsglQTrAfXqifypIF0WotPdLK8B8qN5IkUSnX+W6jicAc3J2YB6g2M6aPwX AVmpZngZiREycyEaWFg7VIsCkh/D0d9gFfqdA81igU83GD5R8xUuJHXyjgI+Y3qejVnY w3qw== Received: by 10.68.202.168 with SMTP id kj8mr11307587pbc.8.1348749689163; Thu, 27 Sep 2012 05:41:29 -0700 (PDT) Received: from [192.168.1.75] (host109-149-32-246.range109-149.btcentralplus.com. [109.149.32.246]) by mx.google.com with ESMTPS id vz8sm3780443pbc.63.2012.09.27.05.41.25 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 27 Sep 2012 05:41:27 -0700 (PDT) Mime-Version: 1.0 (Apple Message framework v1278) From: Tim Watson In-Reply-To: Date: Thu, 27 Sep 2012 13:41:21 +0100 Message-Id: <19CFFB38-1448-4023-AFD7-AD390BEDB...@gmail.com> References: <386854ED-DCB7-4BFC-B586-ABBDCFD91...@erlang-solutions.com> To: =?iso-8859-1?Q?Erik_S=F8e_S=F8rensen?= X-Mailer: Apple Mail (2.1278) Cc: erlang-questions Questions Subject: Re: [erlang-questions] can a program launched with open_port({spawn, Cmd}, Options) remain running after the port closes? X-BeenThere: erlang-questi...@erlang.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Erlang/OTP discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============7483551114363838754==" Errors-To: erlang-questions-boun...@erlang.org Sender: erlang-questions-boun...@erlang.org --===============7483551114363838754== Content-Type: multipart/signed; boundary="Apple-Mail=_8B492D23-63D1-4B67-BC4A-BF93FAA9FC3A"; protocol="application/pgp-signature"; micalg=pgp-sha1 --Apple-Mail=_8B492D23-63D1-4B67-BC4A-BF93FAA9FC3A Content-Type: multipart/alternative; boundary="Apple-Mail=_9A8E5141-6E74-4538-B765-1B1CAAA210B1" --Apple-Mail=_9A8E5141-6E74-4538-B765-1B1CAAA210B1 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=windows-1252 Guys, On 27 Sep 2012, at 13:18, Erik S=F8e S=F8rensen wrote: > 2012/9/27 Jesper Louis Andersen = > I remember this was something I had going. Let me dig code: >=20 > ---- > #!/bin/sh >=20 > (cat && kill 0) | opentracker $* > Nice incantation. I was just about to suggest using a wrapper program, = but I probably wouldn't have thought of that variation. > =20 > ---- >=20 > So the trick is that the =85 && kill 0 part sends a kill signal to all = processes in the current process group. This lets you stop another = process since cat(1) understands what happens when stdin is closed and = handles it accordingly. >=20 > I've only used it in tests though so it may need work for real = programs > Such as replacing "&&" with ";" ? :-) > Just in case someone came along and killed the cat. (Can't at the = moment imagine other scenarios where cat would exit with non-zero return = values, but they probably exist.) >=20 > Also, replace $* with "$@" (including the quotes), for proper handling = of parameters with spaces in them and such. Thanks both of you, I guess that I could drop this in in front of the = required invocation, so you get the required behaviour. The tricky part = here is that the code calling open_port/2 is kind of a generic 'run a = script and monitor things' process, so I'll need to experiment with this = a bit. Thanks for the suggestions anyway - I'll certainly give this a = try.= --Apple-Mail=_9A8E5141-6E74-4538-B765-1B1CAAA210B1 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=windows-1252
2012/9/27= Jesper Louis Andersen <jesper.louis.ander...@erlang-solutions.com>
I remember this was something I had going. Let me dig code:

----
#!/bin/sh

(cat && kill 0) | opentracker $*
Nice = incantation. I was just about to suggest using a wrapper program, but I = probably wouldn't have thought of that = variation.
 
----

So the trick is that the =85 && kill 0 part sends a kill signal = to all processes in the current process group. This lets you stop = another process since cat(1) understands what happens when stdin is = closed and handles it accordingly.

I've only used it in tests though so it may need work for real = programs
Such as replacing "&&" with ";" ? = :-)
Just in case someone came along and killed the cat. (Can't at the = moment imagine other scenarios where cat would exit with non-zero return = values, but they probably exist.)

Also, replace $* with "$@" (including the quotes), for proper = handling of parameters with spaces in them and = such.

Thanks both of = you, I guess that I could drop this in in front of the required = invocation, so you get the required behaviour. The tricky part here is = that the code calling open_port/2 is kind of a generic 'run a script and = monitor things' process, so I'll need to experiment with this a bit. = Thanks for the suggestions anyway - I'll certainly give this a = try.
= --Apple-Mail=_9A8E5141-6E74-4538-B765-1B1CAAA210B1-- --Apple-Mail=_8B492D23-63D1-4B67-BC4A-BF93FAA9FC3A Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP using GPGMail -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.18 (Darwin) iF4EAREIAAYFAlBkSXIACgkQzpZnPFKwjIxBIAD+ISo8eHX2ILVENg1XUNsVMxHD OZqiXkp/MXtkmjasPDIA/Rc/KxgjNmkOtJ30rmhPoafP8kk+NeWQ01DsFUzeZA/F =ELyK -----END PGP SIGNATURE----- --Apple-Mail=_8B492D23-63D1-4B67-BC4A-BF93FAA9FC3A-- --===============7483551114363838754== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ erlang-questions mailing list erlang-questi...@erlang.org http://erlang.org/mailman/listinfo/erlang-questions --===============7483551114363838754==--