From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1448 invoked by alias); 13 Jun 2018 04:10:25 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: X-Seq: 23475 Received: (qmail 29060 invoked by uid 1010); 13 Jun 2018 04:10:24 -0000 X-Qmail-Scanner-Diagnostics: from mail-qk0-f193.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.220.193):SA:0(-1.9/5.0):. Processed in 2.098654 secs); 13 Jun 2018 04:10:24 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_PASS, T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: ericdfreese@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=WQOjsW5zNQYt4I6mpM9HTyT481A0xcy0/yjSp+eW1CY=; b=UjwjYtMq9N7j9Phddaq6maTZgjFXV117DkcM0VzVlmpEb16ZYD+JxA1dmXf9fqDclB rzVOinF0z1gtVcuIV0F/OkdiVu6dleP7heevOA8wNCarw/NxDGDtSNFvfITaytZSM0g8 EauMMgKO7jVYYeWA6QZHIODuvJ1Dh2fV0kdMCGSnURDa0RIUT6rRwZliLmJgUDEIoUXw 1+4KClBk0sJWGNLqQpasAmgJY8MqJWfJPWY76z7d9jR9asFpK0ptpR+m0se0u24tJ4JC CpWZsnbQmvJEfAclZY4Ilp5Pb4+AAbkTEQkuXfwoqqgjYHyzwzZA+Uo0z0CKOaSuwEvD U3Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=WQOjsW5zNQYt4I6mpM9HTyT481A0xcy0/yjSp+eW1CY=; b=gcdwZC3HCV7UaanDM1xfQB1r4r89Q2iU/4JHa+Pkl3qRsmyJGL3VZ8Q2iiffAWTSbq O0u88d8UGhCgf/xiuRZkRbJbcHzN4CfZ7sqiX+7jVBrvNeIObOjoVZMDTK2GAqu1MjrV SOLGQCbFQ5PrwOrOXskanLoJpFccfBsozgcVFZiB5vHNAYLwjqRmpFXtkj9KZumFMELH ocJdfvHhHT9EYdWv215NurkoHCt9k1/iBr/n9DBZtwnMLjVc68HRza2e4nQhYvkaZCht wWroxNDrH5QSOFmOXw+DO28bw/Wx3SbWQqxKBCh5StM4Y6iNsyCh0dI7OdoE35Sv5zc0 712w== X-Gm-Message-State: APt69E20nJmU447cwFhK8oK21ZUpo4IoItJPk1Rs4DKZvxYGSMZdL2KY tRPX+hThbar+QFpUBTJy3UCarX0HvkBYyae6A8Y= X-Google-Smtp-Source: ADUXVKKSHBrbdxdzgV3nBl5zThKyITNAZ15hqUAFzaQmSaPALbZqREqBaIS7PAnGpFZWzPCUcO0AReGqR+xKmV0i6NA= X-Received: by 2002:a37:5a43:: with SMTP id o64-v6mr3085949qkb.211.1528863019625; Tue, 12 Jun 2018 21:10:19 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <20180612113257eucas1p2342f735bcea27bb1009aee1b23c682f0~3ZmPbMrh61839118391eucas1p2G@eucas1p2.samsung.com> References: <20180612113257eucas1p2342f735bcea27bb1009aee1b23c682f0~3ZmPbMrh61839118391eucas1p2G@eucas1p2.samsung.com> From: Eric Freese Date: Tue, 12 Jun 2018 22:09:59 -0600 Message-ID: Subject: Re: Anyone familiar with auto-fu.zsh project? To: Peter Stephenson Cc: Zsh Users Content-Type: multipart/alternative; boundary="00000000000031f167056e7e29fc" --00000000000031f167056e7e29fc Content-Type: text/plain; charset="UTF-8" > We could add it to the $sysparams hash provided by the zsh/system module? It just occurred to me that, with zsh/system, I can have the child process send its pid as the first line of output. Something like: ``` % zmodload zsh/system % exec {FOO}< <(echo $sysparams[pid]; sleep 100; echo foo bar) % read childpid <&$FOO # Get the pid, stored in $childpid % cat <&$FOO # Handle the rest of the output ``` So it may not actually be necessary to add procsubstpid. In fact, the approach above may be preferred if you need to get pids for multiple process substitutions in one command (which I think is possible?). Next question: Is it possible to get the current subshell's pid without having to load the zsh/system module ($sysparams param)? Bash seems to have the $BASHPID variable. Is there anything like that in zsh core? Or, alternatively, is it reasonable to assume that everyone will be able to load the zsh/system module? Background here is that I had a user send a pull request to zsh-autosuggestions requesting we don't depend on zsh/zpty module since some people may not have it installed, so I'm trying to minimize dependencies on non-core modules. Eric Freese 303 875 2359 On Tue, Jun 12, 2018 at 5:32 AM, Peter Stephenson wrote: > On Mon, 11 Jun 2018 19:55:32 -0600 > Eric Freese wrote: > > Do you know if there is any way to get the PID of the process spawned > > for process substitution? It looks like `$!` doesn't hold it as it > > does in bash. > > Hmm, this is obviously useful but I'd be loath simply to make $! do this > as the fact there's an asynchronous process involved is a bit hidden and > the mechanism is rather different from creating a background job, so > that could be confusing. > > We could add it to the $sysparams hash provided by the zsh/system > module? This already contains some PID information. (It's > not strictly a system parameter but I don't think anyone's > going to hold a gun to my head and tell me this hash can only > return the result of immediate system calls.) > > pws > > diff --git a/Doc/Zsh/mod_system.yo b/Doc/Zsh/mod_system.yo > index 7f2009b..a27bab4 100644 > --- a/Doc/Zsh/mod_system.yo > +++ b/Doc/Zsh/mod_system.yo > @@ -255,6 +255,11 @@ Returns the process ID of the parent of the current > process, even in > subshells. Compare tt($PPID), which returns the process ID of the parent > of the main shell process. > ) > +item(tt(procsubstpid))( > +Returns the process ID of the last process started for process > +substitution, i.e. the tt( +tt(>LPAR())var(...)tt(RPAR()) expansions. > +) > enditem() > ) > enditem() > diff --git a/Src/Modules/system.c b/Src/Modules/system.c > index 9fd4d25..7a4f4ee 100644 > --- a/Src/Modules/system.c > +++ b/Src/Modules/system.c > @@ -772,6 +772,8 @@ fillpmsysparams(Param pm, const char *name) > num = (int)getpid(); > } else if (!strcmp(name, "ppid")) { > num = (int)getppid(); > + } else if (!strcmp(name, "procsubstpid")) { > + num = (int)procsubstpid; > } else { > pm->u.str = dupstring(""); > pm->node.flags |= PM_UNSET; > @@ -805,6 +807,8 @@ scanpmsysparams(UNUSED(HashTable ht), ScanFunc func, > int flags) > func(&spm.node, flags); > fillpmsysparams(&spm, "ppid"); > func(&spm.node, flags); > + fillpmsysparams(&spm, "procsubstpid"); > + func(&spm.node, flags); > } > > static struct mathfunc mftab[] = { > diff --git a/Src/exec.c b/Src/exec.c > index 963b0a5..d445278 100644 > --- a/Src/exec.c > +++ b/Src/exec.c > @@ -174,6 +174,11 @@ mod_export int zleactive; > /**/ > pid_t cmdoutpid; > > +/* pid of last process started by <(...), >(...) */ > + > +/**/ > +mod_export pid_t procsubstpid; > + > /* exit status of process undergoing 'process substitution' */ > > /**/ > @@ -4850,6 +4855,7 @@ getproc(char *cmd, char **eptr) > return NULL; > if (!out) > addproc(pid, NULL, 1, &bgtime); > + procsubstpid = pid; > return pnam; > } > closem(FDT_UNUSED, 0); > @@ -4887,6 +4893,7 @@ getproc(char *cmd, char **eptr) > { > addproc(pid, NULL, 1, &bgtime); > } > + procsubstpid = pid; > return pnam; > } > entersubsh(ESUB_ASYNC|ESUB_PGRP); > @@ -4937,6 +4944,7 @@ getpipe(char *cmd, int nullexec) > } > if (!nullexec) > addproc(pid, NULL, 1, &bgtime); > + procsubstpid = pid; > return pipes[!out]; > } > entersubsh(ESUB_PGRP); > @@ -6172,6 +6180,7 @@ execsave(void) > es->cmdoutpid = cmdoutpid; > es->cmdoutval = cmdoutval; > es->use_cmdoutval = use_cmdoutval; > + es->procsubstpid = procsubstpid; > es->trap_return = trap_return; > es->trap_state = trap_state; > es->trapisfunc = trapisfunc; > @@ -6207,6 +6216,7 @@ execrestore(void) > cmdoutpid = en->cmdoutpid; > cmdoutval = en->cmdoutval; > use_cmdoutval = en->use_cmdoutval; > + procsubstpid = en->procsubstpid; > trap_return = en->trap_return; > trap_state = en->trap_state; > trapisfunc = en->trapisfunc; > diff --git a/Src/zsh.h b/Src/zsh.h > index 8535d48..8e7f20b 100644 > --- a/Src/zsh.h > +++ b/Src/zsh.h > @@ -1095,6 +1095,7 @@ struct execstack { > pid_t cmdoutpid; > int cmdoutval; > int use_cmdoutval; > + pid_t procsubstpid; > int trap_return; > int trap_state; > int trapisfunc; > > --00000000000031f167056e7e29fc--