Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Job control commands accepting PID



In the man page it states that any job control command can address a job via
PID as well as the % constructs.  In the source, only 'wait' has the support
for this.  The following patch remedies this deficiency.  Any proper integer
argument with no leading '%' is interpreted as a PID.  The selected job is the
one which contains that PID.  No other % semantics are changed. I haven't
tested it a whole lot, but it seems to work. The benefit is that you can do
things like "foo & disown $!". [ Just "disown" fails if for some reason "foo"
is not the "current" job. ]  I just joined the list so forgive me if this is
already done or redundant in some other way.

Chuck


diff -r zsh-2.6-beta11/Src/builtin.c zsh-2.6-beta11-cb/Src/builtin.c
753c753,754
<     int jobnum;
---
>     int jobnum, pid_num;
>     char *last_valid;
754a756,766
>     /* search for PID */
>     pid_num = strtol(s, &last_valid, 10);
>     if (*last_valid == '\0') {
> 	struct process* p;
> 	for (jobnum = MAXJOB - 1; jobnum >= 0; jobnum--)
> 	    if (jobtab[jobnum].stat && jobnum != thisjob)
> 		for(p = jobtab[jobnum].procs; p; p = p->next)
> 		    if (p->pid == pid_num)
> 			return jobnum;
>     }
>     /* search for job name */



Messages sorted by: Reverse Date, Date, Thread, Author