Skip to main content

zfork

Function zfork 

Source
pub fn zfork(ts: Option<&mut timespec>) -> i32
Expand description

Port of static pid_t zfork(struct timespec *ts) from Src/exec.c:349.

C body:

pid_t pid;
if (thisjob != -1 && thisjob >= jobtabsize - 1 && !expandjobtab()) {
    zerr("job table full");
    return -1;
}
if (ts) zgettime_monotonic_if_available(ts);
queue_signals();
pid = fork();
unqueue_signals();
if (pid == -1) {
    zerr("fork failed: %e", errno);
    return -1;
}
#ifdef HAVE_GETRLIMIT
if (!pid) setlimits(NULL);
#endif
return pid;

fork(2) wrapper with jobtab capacity check + child rlimit re-application. Used by every subshell-spawning path: pipelines, process substitution, async commands, command substitution.