tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

shell jobs -p



I could probably as well directly mail kre@, but who knows.

The objective was to write s shell script that parallelized invocations of 
some command, but only up to a certain number of jobs running in parallel.
There were two ideas to implement this, one using the jobs utility to track 
the current invocations and one to manually track them on a list.

I ran into a number of problems with the "jobs" variant where I'm unsure of 
whether I was running into corner cases undefined by POSIX or plain bugs in 
certain shells.

1. When you background a job (with &), and later, the job has finished
	a) in the sense that it's a shell function that has returned
	b) in the sense that it's an external process that called exit(3)
but the script has not wait-ed for the job (wait meaning the utility, not 
the system call)
is the job then supposed to show up in "jobs -p" output?
In bash, at least for a), the job does show up until you call jobs without -p.
In ash and dash, it doesn't show up.

2. SUS says "The jobs utility does not work as expected when it is operating 
in its own utility execution environment". Indeed, in dash, $(jobs -p) 
outputs nothing, rendering jobs useless for non-interactive use. But SUS 
also says "Usage such as $(jobs -p) provides a way of ...". So, does dash's 
behaviour qualify as a bug?. 


I attach both implementations, maybe there are other useful comments.

Attachment: parallel.jobs.sh
Description: Bourne shell script

Attachment: parallel.list.sh
Description: Bourne shell script



Home | Main Index | Thread Index | Old Index