[Top][All Lists]

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

Re: Checking executability for asynchronous commands

From: Chet Ramey
Subject: Re: Checking executability for asynchronous commands
Date: Tue, 29 Dec 2020 10:23:07 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.6.0

On 12/28/20 1:23 AM, Markus Elfring wrote:

I got another programming concern:
Process identifications are a system resource.
The exit status is preserved until this information will eventually be used
for corresponding data processing.
How many processes can a selected system configuration handle?

This is a hard question to answer. It depends on the system, its
configuration, the PID allocation rate, and the allocation strategy.

PIDs are indeed allocated by the system, using different strategies. Many
systems use random allocation through a 16- or 32-bit space (whatever a
pid_t is). It's possible to receive the same PID for two different spawned
child processes before enumerating the entire PID space. One guarantee is
that the system won't reallocate a given PID until it's been reaped, and
its parent gets its exit status, so a script will usually have the
opportunity to obtain the status information it wants.

Bash will save some number of exit statuses corresponding to terminated
asynchronous child processes, and those statuses are retrievable using
`wait'. That number varies -- POSIX says you need to save at least
CHILD_MAX statuses, but bash will look at its nproc resource limit (using
sysconf(3)) and try to save that many, up to a max of 32K in bash-5.1. This
will be sufficient in most cases.

If a script saves exit status information it retrieves using `wait' into
shell variables, it can obviously save as many statuses as it wants.

So the answer is, as it usually is, "it depends."

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]