From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9337 invoked by alias); 25 Jun 2014 14:34:12 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 32801 Received: (qmail 25152 invoked from network); 25 Jun 2014 14:34:08 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:content-type:subject:message-id:date:to:mime-version; bh=0obqolOHdvSX7vrLUf47DuFXcewUKnIn4BWv9uHTlik=; b=B7qX7M9UDbwx8cCqt+2DyKhKrtkox1VpfdAf5ufrwJV2p9ert0IRHX2BT/sXojjxZe 5/qWabGYrq5LGl2OnTg2G5Bpfe+9+rEXQaGYijOqZd/+0LhdDKLjWEmd1lxb3QDzxB8Q g+ENtee1aj2EkMMSnB9Laz/etK0YGLZK7MrBVijX8ZsjcsR5lxoBcUEpFYr3aMjQiDOT jE7ePQo9VqD8lRh7k0T5Rx/1tmFaGsMKP9lCtJzc5/ympjoQLNcRDnLVlwLSKmdaxOBU ZyNpt7jJ1l3FRDOekTdB2KL6wgkANzuUVYF+dShVKMsK1WUsHDkkAc82TBQo9EK9d2nO n50g== X-Received: by 10.66.66.135 with SMTP id f7mr12491790pat.22.1403706844898; Wed, 25 Jun 2014 07:34:04 -0700 (PDT) Sender: Dave Yost From: Dave Yost X-Google-Original-From: Dave Yost Content-Type: multipart/alternative; boundary="Apple-Mail=_AEB8AFB2-F6FA-4472-8353-5DFFFB68CF56" Subject: shell function in the background? Message-Id: <2C39FCD4-02E6-4957-B292-486065C24639@yost.com> Date: Wed, 25 Jun 2014 07:34:01 -0700 To: zsh-workers@zsh.org Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) X-Mailer: Apple Mail (2.1878.6) --Apple-Mail=_AEB8AFB2-F6FA-4472-8353-5DFFFB68CF56 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=windows-1252 Can a shell function tell if it=92s part of a pipeline running in the = background?=20 I want to write a shell function that traps SIGCONT and does one thing = or another thing depending on whether the function is CONTinuing in the = background. Can=92t see how to do it. Furthermore, it=92s not clear to me why a backgrounded function thinks = its pid is the pid of the shell that spawned it. 0 Wed 0:12:34 DaveBook yost /tmp 250 Z% function foo() { print foo says pid is $$ sleep 2 } 0 Wed 0:12:56 DaveBook yost /tmp 251 Z% foo & ps xl -t ttys004 | sort -k 2 [1] 26183 foo says pid is 25935 UID PID PPID CPU PRI NI VSZ RSS WCHAN STAT TT TIME = COMMAND 0 25934 226 0 143 0 2503604 2316 - Ss s004 0:00.01 = login -pf yost /bin/zsh 502 25935 25934 0 31 0 2500064 2512 - S s004 0:00.14 = -zsh 502 26183 25935 0 163 5 2500064 588 - SN s004 0:00.00 = -zsh 0 26184 25935 0 45 0 2433268 644 - R+ s004 0:00.00 = ps xl -t ttys004 502 26185 26183 0 1074014208 5 2432764 500 - SN s004 = 0:00.00 sleep 2 502 26186 25935 0 1074104586 0 2432800 500 - R+ s004 = 0:00.00 sort -k 2 0 Wed 0:13:00 DaveBook yost /tmp 252 Z%=20 [1] + 26183 done foo 0 Wed 0:13:02 DaveBook yost /tmp 252 Z% print pid is $$ pid is 25935 0 Wed 0:21:00 DaveBook yost /tmp 253 Z%=20 I get the same thing even if I do this function foo() {( print foo says pid is $$ sleep 2 )} foo & or this function foo() { ( print foo says pid is $$ sleep 2 ) & } foo --Apple-Mail=_AEB8AFB2-F6FA-4472-8353-5DFFFB68CF56--