From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1895 invoked by alias); 25 Jun 2014 15:56:06 -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: 32802 Received: (qmail 26904 invoked from network); 25 Jun 2014 15:55:54 -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=-2.6 required=5.0 tests=BAYES_00,HTML_MESSAGE, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=YOaJXPnfLAShmQpqFRPNgz8URDg+EFhoOIvDYQbCJwI=; b=lETm2dNQGxmj9qrr0ri4ST5YwZdz7IhVp+Os/jF4mQ5y/QU1ud7+cKkLY56GBJ9lC5 LBG60coccOKnMezpHkyLeqfpad81DXayy/mAQkLw4pccRRUfpqTd+P+XO3/2AtZDrRxn RuQZefOcONPAMoh7uv9BhfSz0nPYMStTFZU45dL9sao4ckHoCm05FmBPEqGJ3PY+gsmg bo/bJf5OxXRLf73TRU5rbi+sfQg/t/+0QfGXpaXu56yBhMmHN/e1AHVHb6ATP7upjvAB 6TZyHuV36XVyVVBYhnWMj5AYF1EYsjZAqlZ5Q8ejIEWAwGqqYC9o8a7gAldlQfRJiW/9 /RDg== X-Gm-Message-State: ALoCoQkcfJg4FJx+cbm0uSNskggNB8CBvNGd9ArzCCpU0ai3oCGx/kSOjUbkaIyb6hSxrfBMHv37 MIME-Version: 1.0 X-Received: by 10.140.30.195 with SMTP id d61mr12306593qgd.62.1403711749872; Wed, 25 Jun 2014 08:55:49 -0700 (PDT) In-Reply-To: <2C39FCD4-02E6-4957-B292-486065C24639@yost.com> References: <2C39FCD4-02E6-4957-B292-486065C24639@yost.com> Date: Wed, 25 Jun 2014 08:55:49 -0700 Message-ID: Subject: Re: shell function in the background? From: Bart Schaefer To: Dave Yost Cc: zsh-workers@zsh.org Content-Type: multipart/alternative; boundary=001a113a6e8637f90c04fcab1c5e --001a113a6e8637f90c04fcab1c5e Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Jun 25, 2014 9:34 AM, "Dave Yost" wrote: > > > Can a shell function tell if it=E2=80=99s part of a pipeline running in t= he background? That's a tricky question because all parts of a pipeline run "in the background" except for the last (first, in most shells other than zsh) command. So you're really asking whether the function can tell if some other process downstream of it has been put in the background. There's no direct way to do that. > 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. I'm not sure that would work for you anyway, because the timing of delivery of the signal to your function and to other jobs in the pipeline is not deterministic. Also, because of vagaries of job control and memory management, the shell trap handler for CONT might not be called immediately= . Is there some other condition related to being in the background that you might test instead? I.e. why does backgrounding require different behavior= ? > Furthermore, it=E2=80=99s not clear to me why a backgrounded function thi= nks its pid is the pid of the shell that spawned it. That's the way the $$ variable is defined by the standard and is how all Unix shells have always behaved. If you "zmodload zsh/system" the parameter $pid becomes available and has the value you want. --001a113a6e8637f90c04fcab1c5e--