Re: (bash) How (really!) does the "current job" get determined?

Liste des GroupesRevenir à cu shell 
Sujet : Re: (bash) How (really!) does the "current job" get determined?
De : gazelle (at) *nospam* shell.xmission.com (Kenny McCormack)
Groupes : comp.unix.shell
Date : 04. Oct 2024, 14:13:59
Autres entêtes
Organisation : The official candy of the new Millennium
Message-ID : <vdopmn$2ptf8$1@news.xmission.com>
References : 1 2
User-Agent : trn 4.0-test77 (Sep 1, 2010)
In article <20241003170607.397@kylheku.com>,
Kaz Kylheku  <643-408-1753@kylheku.com> wrote:
On 2024-10-03, Kenny McCormack <gazelle@shell.xmission.com> wrote:
Note: This is a "How do things really work - in the real world?", rather
than a "What does the manual say about how things work?" sort of thread.
>
The manual says the answer is "The job most recently started in the
background or most recently stopped."  This is not always the case.
>
Observe (this is bash version 5.2.15) (and "j" is aliased to "jobs -l"):
>
It looks buggered.

Indeed it does.  What this means from a scripting programmer's
point-of-view is that you can't count on it.  You can't rely on the job you
just launched being the "current job".  Thus, you have to convert $! into a
job id, via something like:

    jobs -l | awk $!' == $2 { print substr($0,2)+0 }'

From the bash developers point-of-view, the question becomes: What specific
set of circumstances triggers this?

Note also that the underlying problem here is that while most of the "job
related" commands that take a "job spec" will take either something like %1
or an actual pid, but the "fg" command only takes %n.  So, if you want to
fg the most recent job, you need to obtain the job id (via the command line
above), before passing it to "fg".  Note that "fg" with no arg at all would
fg the wrong job.

It must be that Bash has no test cases covering the documented
requirements in this area adequate enough to catch what you have found.
>
Is this automatically tested at all?
>
Testing interactive job control features pretty much requires Bash to be
behind a pseudo-tty; driven by expect or something like it.

Indeed.  Good point.

(Or else at least a unit test is required where the function that
identifies the current job is tested in isolation, with the various
conditions mocked up: suspended job introduced while existing job is
stopped, etc.)

Yes.

--
Trump could say he invented gravity, and 40% of the country would believe him...
This is where we are at, ladies and gentlemen.

Date Sujet#  Auteur
4 Oct 24 * (bash) How (really!) does the "current job" get determined?33Kenny McCormack
4 Oct 24 `* Re: (bash) How (really!) does the "current job" get determined?32Kaz Kylheku
4 Oct 24  `* Re: (bash) How (really!) does the "current job" get determined?31Kenny McCormack
4 Oct 24   `* Re: (bash) How (really!) does the "current job" get determined?30Kaz Kylheku
4 Oct 24    +* Expand your mind (Was: (bash) How (really!) does the "current job" get determined?)2Kenny McCormack
5 Oct 24    i`- Re: Expand your mind (Was: (bash) How (really!) does the "current job" get determined?)1Kaz Kylheku
4 Oct 24    `* Re: (bash) How (really!) does the "current job" get determined?27Christian Weisgerber
4 Oct 24     `* Re: (bash) How (really!) does the "current job" get determined?26Janis Papanagnou
5 Oct 24      `* Re: (bash) How (really!) does the "current job" get determined?25Christian Weisgerber
5 Oct 24       +* Re: (bash) How (really!) does the "current job" get determined?2Kaz Kylheku
10 Oct 24       i`- Re: (bash) How (really!) does the "current job" get determined?1Kaz Kylheku
5 Oct 24       +- Re: (bash) How (really!) does the "current job" get determined?1Keith Thompson
5 Oct 24       +* Re: (bash) How (really!) does the "current job" get determined?13Kenny McCormack
5 Oct 24       i+* Re: (bash) How (really!) does the "current job" get determined?11Christian Weisgerber
5 Oct 24       ii`* pid ranges (Was: (bash) How (really!) does the "current job" get determined?)10Kenny McCormack
7 Oct 24       ii `* Re: pid ranges (Was: (bash) How (really!) does the "current job" get determined?)9Janis Papanagnou
7 Oct 24       ii  +- Re: pid ranges (Was: (bash) How (really!) does the "current job" get determined?)1marrgol
7 Oct 24       ii  `* Re: pid ranges (Was: (bash) How (really!) does the "current job" get determined?)7Kenny McCormack
7 Oct 24       ii   `* Re: pid ranges (Was: (bash) How (really!) does the "current job" get determined?)6Janis Papanagnou
7 Oct 24       ii    `* Re: pid ranges5Richard Kettlewell
7 Oct 24       ii     `* [OT] PIDs for Linux threads (was Re: pid ranges)4Janis Papanagnou
7 Oct 24       ii      +- Re: [OT] PIDs for Linux threads (was Re: pid ranges)1Kenny McCormack
7 Oct 24       ii      +- Re: [OT] PIDs for Linux threads (was Re: pid ranges)1Lew Pitcher
7 Oct 24       ii      `- Re: PIDs for Linux threads (was Re: pid ranges)1Lawrence D'Oliveiro
6 Oct 24       i`- Re: (bash) How (really!) does the "current job" get determined?1Kaz Kylheku
7 Oct 24       +* Re: (bash) How (really!) does the "current job" get determined?5Janis Papanagnou
7 Oct 24       i`* Re: (bash) How (really!) does the "current job" get determined?4Kenny McCormack
7 Oct 24       i `* Re: (bash) How (really!) does the "current job" get determined?3Janis Papanagnou
7 Oct 24       i  `* bash/ksh differences (fg and other job control commands) (Was: (bash) How (really!) does the "current job" get determined?)2Kenny McCormack
7 Oct 24       i   `- Re: bash/ksh differences (fg and other job control commands) (Was: (bash) How (really!) does the "current job" get determined?)1Janis Papanagnou
7 Oct 24       +- Re: (bash) How (really!) does the "current job" get determined?1Helmut Waitzmann
8 Oct 24       +- Re: (bash) How (really!) does the "current job" get determined?1Richard Harnden
8 Oct 24       `- Re: (bash) How (really!) does the "current job" get determined?1Kaz Kylheku

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal