zsh-users
 help / color / mirror / code / Atom feed
* fg does not resume most recent job when started from a function
@ 2021-01-20 19:02 Samir Benmendil
  0 siblings, 0 replies; only message in thread
From: Samir Benmendil @ 2021-01-20 19:02 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 1386 bytes --]

Hello,

When multiple jobs are being started via a function, suspending and 
resuming them behaves a bit oddly. The most recently suspended job seems 
to be placed at the end of the jobs queue and is therefore not the one 
being resumed by a fg call.

For example:

% function print_s { watch echo $1 }
% print_s one  # suspend command with ^Z
% print_s two  # suspend command with ^Z
% jobs
[1]  - suspended  
[3]  + suspended
% fg # resumes print_s two as expected, suspend it with ^Z
[3]  - 214167 continued

[3]  - 214167 suspended
[3]  - 214167 suspended
% jobs
[1]  + suspended  
[3]  - suspended
% fg # resumes print_s one?! suspend with ^Z
[1]  - 214151 continued

[1]  - 214151 suspended
[1]  - 214151 suspended
% fg # resumes print_s two?! fg, ^Z will alternate between jobs
[3]  - 214167 continued

[3]  - 214167 suspended
[3]  - 214167 suspended

Notice also that `jobs` does not list any command names.

Running the same watch command directly rather through a function 
results in ^Z/fg behaving as expected, suspending/resuming the latest 
job.

I've tried coming up with an example that would automatically suspend 
the command by backgrounding it and reading from stdin.

% function read_bg { read & }

This does indeed suspend read immediately but the behaviour described 
above is not exhibited.

Best Regards,
Samir

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-01-20 19:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-20 19:02 fg does not resume most recent job when started from a function Samir Benmendil

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).