Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

fg does not resume most recent job when started from a function



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: signature.asc
Description: PGP signature



Messages sorted by: Reverse Date, Date, Thread, Author