United States-English |
|
|
HP-UX Reference > Ffork(2)HP-UX 11i Version 3: February 2007 |
|
NAMEfork() — create a new process DESCRIPTIONThe fork() system call causes the creation of a new process. The new child process is created with exactly one thread or lightweight process. The new child process contains a replica of the calling thread (if the calling process is multi-threaded) and its entire address space, possibly including the state of mutexes and other resources. If the calling process is multi-threaded, the child process may only execute async-signal safe functions until one of the exec functions is called. Fork handlers may be installed via pthread_atfork() in order to maintain application invariants across fork() calls (i.e, release resources such as mutexes in the child process). The child process inherits the following attributes from the parent process:
Each of the child's file descriptors shares a common open file description with the corresponding file descriptor of the parent. This implies that changes to the file offset, file access mode, and file status flags of file descriptors in the parent also affect those in the child, and vice-versa. The child process differs from the parent process in the following ways:
The vfork() system call can be used to fork processes more quickly than fork(), but has some restrictions. See vfork(2) for details. If a parent and child process both have a file opened and the parent or child closes the file, the file is still open for the other process. Security RestrictionsThis system call requires the LIMIT privilege in order to exceed the per-user process limit Processes owned by the superuser have this privilege. Processes owned by other users may have this privilege, depending on system configuration. See privileges(5) for more information about privileged access on systems that support fine-grained privileges. RETURN VALUEUpon successful completion, fork() returns a value of 0 to the child process and returns the process ID of the child process to the parent process. Otherwise, a value of -1 is returned to the parent process, no child process is created, and errno is set to indicate the error. The parent and child processes resume execution immediately after the fork() call; they are distinguished by the value returned by fork(). ERRORSIf fork() fails, errno is set to one of the following values.
WARNINGSStandard I/O streams (see stdio(3S)) are duplicated in the child. Therefore, if fork() is called after a buffered I/O operation without first closing or flushing the associated standard I/O stream (see fclose(3S)), the buffered input or output might be duplicated. DEPENDENCIESHP Process Resource ManagerIf the optional HP Process Resource Manager (PRM) software is installed and configured, the child process inherits the parent's process resource group ID. See prmconfig(1) for a description of how to configure HP PRM, and prmconf(4) for the definition of process resource group. SEE ALSOcoreadm(1M), acct(2), chroot(2), coreadm(2), exec(2), exit(2), fcntl(2), getgroups(2), lockf(2), nice(2), plock(2), profil(2), pthread_atfork(3T), ttrace(2), rtprio(2), semop(2), setpgrp(2), setuid(2), shmop(2), times(2), ulimit(2), umask(2), vfork(2), wait(2), fclose(3S), stdio(3S), acct(4), compartments(5), privileges(5), signal(5). HP Process Resource Manager: prmconfig(1), prmconf(4) in HP Process Resource Manager User's Guide. |
Printable version | ||
|