NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: bin/57894: sh(1): PID obtained with jobs -p is always 0 on NetBSD 10.0 RC



The following reply was made to PR bin/57894; it has been noted by GNATS.

From: Robert Elz <kre%munnari.OZ.AU@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: 
Subject: Re: bin/57894: sh(1): PID obtained with jobs -p is always 0 on NetBSD 10.0 RC
Date: Wed, 31 Jan 2024 02:00:44 +0700

     Date:        Tue, 30 Jan 2024 13:35:00 +0000 (UTC)
     From:        koichi%nksm.name@localhost
     Message-ID:  <20240130133500.967921A923A%mollari.NetBSD.org@localhost>
 
   | >Synopsis:       sh(1): PID obtained with jobs -p is always 0 on NetBSD 10.0 RC
 
   | $ sh -c 'sleep 3 & echo $!; jobs -l; jobs -p'
   | 7975
   | [1] + 7975 Running            sleep 3 &
   | 0
 
 This wasn't intended, and I am about to commit a fix, but at
 least according to POSIX, that isn't required to work.
 
    -p Display only the process IDs for the process group leaders of job-control
       background jobs and the process IDs associated with non-job-control
       background jobs (if supported).
 
 Non-interactive shells (which is what that is) don't enable job control,
 so that sleep 3 is a non-job-control background job, and we're not required
 to support -p for those.
 
 If job control were enabled, as in
 
 	sh -c 'set -m; sleep 3 & echo $!; jobs -l; jobs -p'
 
 then it would work (in -10, and HEAD, without the coming fix).
 
 The issue is a fix that was making sure the correct value was
 always output for job-control jobs (there were ways, in more complex
 examples, to get the wrong pid printed).   But the non-job-control
 ones just got forgotten.   Oops...
 
 For now, in the non-job-control case, sh will just do what it used to do
 (while still doing it the new way for job-controlled background jobs).
 
 


Home | Main Index | Thread Index | Old Index