View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0001966 | 1003.1(2013)/Issue7+TC1 | Shell and Utilities | public | 2025-12-21 11:17 | 2025-12-21 11:17 |
| Reporter | stephane | Assigned To | |||
| Priority | normal | Severity | Objection | Type | Clarification Requested |
| Status | New | Resolution | Open | ||
| Name | Stephane Chazelas | ||||
| Organization | |||||
| User Reference | |||||
| Section | current/previous job in basedefs, jobs, fg, bg utilities | ||||
| Page Number | (page or range of pages) | ||||
| Line Number | (Line or range of lines) | ||||
| Interp Status | |||||
| Final Accepted Text | |||||
| Summary | 0001966: Current/previous job definition scattered and ambiguous | ||||
| Description | POSIX defines the "current job" as: > In the context of job control, the job that will be used as > the default for the fg or bg utilities. (https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/basedefs/V1_chap03.html#tag_03_93). With the fg utility specification stating: > no job_id operand is given, the job_id for the job that was > most recently suspended, placed in the background, or run as a > background job shall be used. (https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/utilities/fg.html) Previous job is defined as: > In the context of job control, the job that will be used as > the default for the fg or bg utilities if the current job > exits. (https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/basedefs/V1_chap03.html#tag_03_286) We however need to refer to the "jobs" utility specification to make some sense out of that: > The character '+' identifies the job that would be used as a > default for the fg or bg utilities; this job can also be > specified using the job_id %+ or "%%". The character '-' > identifies the job that would become the default if the > current default job were to exit; this job can also be > specified using the job_id %-. For other jobs, this field is a > <space>. At most one job can be identified with '+' and at > most one job can be identified with '-'. If there is any > suspended job, then the current job shall be a suspended job. > If there are at least two suspended jobs, then the previous > job also shall be a suspended job. (https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/utilities/jobs.html) That suggests "the job_id for the job that was most recently suspended, placed in the background, or run as a background job shall be used" from the "current job" definition is to be interpreted as: 1. the most recently suspend job if there are suspended jobs 2. if not, the job most recently "placed in the background" (whatever that means) if there are some. 3. if not the job most recently started in background. As far I know, the only ways to "place" a job in the background are to suspend them whilst they are in foreground or start them in background in the first place, so there are several ways to interpret that "2" above: a) 3 is redundant but it's to emphasis that it's the time of last suspend (whilst in foreground, or not, to be clarified) that's important for those jobs that have been suspended. b) it's to say that jobs that have ever been suspended (have ever been in foreground before) take precedence over jobs that were started in background in the first place and were never suspended. c) maybe "resumed in background" (by way of bg or any other way SIGCONT is delivered) was intended instead of "placed in background". The Rationale there also has: > The job control features provided by bg, fg, and jobs are > based on the KornShell. The standard developers examined the > characteristics of the C shell versions of these utilities and > found that differences exist. Despite widespread use of the C > shell, the KornShell versions were selected for this volume of > POSIX.1-2024 to maintain a degree of uniformity with the rest > of the KornShell features selected (such as the very popular > command line editing features). However, testing ksh88 from Solaris 11.4's /usr/xpg4/bin/sh and ksh93u+m/1.0.8 2024-01-01, those are clearly not compliant, as $ sleep 1001 ^Z[1] + Stopped sleep 1001 $ sleep 1002 & [2] 20308 $ jobs [2] + Running sleep 1002 & [1] - Stopped sleep 1001 The suspended job is not made the current job, whilst that's the part that is clearly unambiguous in the spec in the description of the jobs utility. In practice, I see a lot of variation between implementations, and I don't think I've come across one that fully implements any of the interpretations listed above. | ||||
| Desired Action | Change the definition of "current job" to: Either make (carry on making) ksh non-compliant with: > If there are any suspended job, the most recently suspended > job. If not, one of the jobs running in background. It's > unspecified whether that's the most recently started, most > recently suspended (in the past) or most recently resumed or > combination thereof. Or to also account for ksh (mksh is yet different from ksh88/ksh93) with: > If there are any suspended job, then the current job shall > be the most recently suspended job as long as it's still in > a suspended state and no other job was started since it was > last suspended. Otherwise, it is unspecified which job shall > be the current job. Adding a: > users may refer to the output of the jobs utility to know > which is the current and previous job With a reference to the jobs utility specification could be useful. Maybe clarify the definition of "previous job" to something like: > what the current job would be in the absence of whichever job > is currently appointed as the current job. Then update the "jobs" / "fg" / "bg" specification to refer to those definitions. And either remove the jobs utility rationale section about the specification being based on the Korn shell rather than C shell or clarify which of the C / Korn shell behaviours were selected in the POSIX specification. | ||||
| Tags | No tags attached. | ||||
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2025-12-21 11:17 | stephane | New Issue |