sh: jobs -p: Do not ask the kernel for the pgid.
The getpgid() call will fail if the first process in the job has already terminated, resulting in output of "-1". The pgid of a job is always the pid of the first process in the job and other code already relies on this.
This commit is contained in:
parent
9d67d2214f
commit
5af61b5251
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=216199
@ -308,7 +308,6 @@ showjob(struct job *jp, pid_t pid, int mode)
|
|||||||
struct procstat *ps;
|
struct procstat *ps;
|
||||||
struct job *j;
|
struct job *j;
|
||||||
int col, curr, i, jobno, prev, procno;
|
int col, curr, i, jobno, prev, procno;
|
||||||
pid_t ppid;
|
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
procno = (mode == SHOWJOBS_PGIDS) ? 1 : jp->nprocs;
|
procno = (mode == SHOWJOBS_PGIDS) ? 1 : jp->nprocs;
|
||||||
@ -323,9 +322,7 @@ showjob(struct job *jp, pid_t pid, int mode)
|
|||||||
#endif
|
#endif
|
||||||
for (ps = jp->ps ; ; ps++) { /* for each process */
|
for (ps = jp->ps ; ; ps++) { /* for each process */
|
||||||
if (mode == SHOWJOBS_PIDS || mode == SHOWJOBS_PGIDS) {
|
if (mode == SHOWJOBS_PIDS || mode == SHOWJOBS_PGIDS) {
|
||||||
ppid = (mode == SHOWJOBS_PIDS) ? ps->pid :
|
out1fmt("%d\n", (int)ps->pid);
|
||||||
getpgid(ps->pid);
|
|
||||||
out1fmt("%d\n", (int)ppid);
|
|
||||||
goto skip;
|
goto skip;
|
||||||
}
|
}
|
||||||
if (mode != SHOWJOBS_VERBOSE && ps != jp->ps && pid == 0)
|
if (mode != SHOWJOBS_VERBOSE && ps != jp->ps && pid == 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user