zsh-users
 help / color / mirror / 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

zsh-users

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.vuxu.org/zsh-users

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 zsh-users zsh-users/ http://inbox.vuxu.org/zsh-users \
		zsh-users@zsh.org
	public-inbox-index zsh-users

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.users


code repositories for the project(s) associated with this inbox:

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

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git