создать дочерний процесс (create a child process)
Ошибки (баги) (Bugs)
GNU C library versions 2.3.4 up to and including 2.24 contained a
wrapper function for getpid(2) that performed caching of PIDs.
This caching relied on support in the glibc wrapper for clone
(),
but limitations in the implementation meant that the cache was
not up to date in some circumstances. In particular, if a signal
was delivered to the child immediately after the clone
() call,
then a call to getpid(2) in a handler for the signal could return
the PID of the calling process ("the parent"), if the clone
wrapper had not yet had a chance to update the PID cache in the
child. (This discussion ignores the case where the child was
created using CLONE_THREAD
, when getpid(2) should return the same
value in the child and in the process that called clone
(), since
the caller and the child are in the same thread group. The
stale-cache problem also does not occur if the flags argument
includes CLONE_VM
.) To get the truth, it was sometimes necessary
to use code such as the following:
#include <syscall.h>
pid_t mypid;
mypid = syscall(SYS_getpid);
Because of the stale-cache problem, as well as other problems
noted in getpid(2), the PID caching feature was removed in glibc
2.25.