Lines Matching refs:code
26 The @code{system} function provides a simple, portable mechanism for
49 The easy way to run another program is to use the @code{system}
93 it always uses the default shell @code{sh} to run the command.
94 In particular, it searches the directories in @code{PATH} to find
95 programs to execute. The return value is @code{-1} if it wasn't
98 status code can be interpreted.
105 descriptors, semaphores or whatever) at the time @code{system} is
107 until the program ends. To avoid this calls to @code{system} should be
112 The @code{system} function is declared in the header file
119 @w{@code{system (NULL)}}; if the return value is nonzero, a command
122 The @code{popen} and @code{pclose} functions (@pxref{Pipe to a
123 Subprocess}) are closely related to the @code{system} function. They
139 @code{posix_spawn}, @code{fork}, @code{_Fork} or @code{vfork} is called.
140 (The @code{system} and @code{popen} also create new processes internally.)
141 Due to the name of the @code{fork} function, the act of creating a new
150 explicitly after the fork operation, by calling @code{wait} or
151 @code{waitpid} (@pxref{Process Completion}). These functions give you
153 exit status code.
156 its parent process, at the point where the @code{fork} or @code{_Fork}
157 call returns. You can use the return value from @code{fork} or
158 @code{_Fork} to tell whether the program is running in the parent process
164 @code{exec} functions; see @ref{Executing a File}. The program that the
175 @code{pid_t}. A process ID is allocated to each process when it is
190 On Linux, threads created by @code{pthread_create} also receive a
203 You can get the process ID of a process by calling @code{getpid}. The
204 function @code{getppid} returns the process ID of the parent of the
213 The @code{pid_t} data type is a signed integer type which is capable
214 of representing a process ID. In @theglibc{}, this is an @code{int}.
220 The @code{getpid} function returns the process ID of the current process.
226 The @code{getppid} function returns the process ID of the parent of the
233 The @code{gettid} function returns the thread ID of the current
244 The @code{fork} function is the primitive for creating a process.
260 The @code{fork} function creates a new process.
263 processes and both see @code{fork} return, but with different values: it
264 returns a value of @code{0} in the child process and returns the child's
267 If process creation failed, @code{fork} returns a value of @code{-1} in
268 the parent process. The following @code{errno} error conditions are
269 defined for @code{fork}:
271 @table @code
275 @code{RLIMIT_NPROC} resource limit, which can usually be increased;
324 The @code{_Fork} function is similar to @code{fork}, but it does not invoke
325 any callbacks registered with @code{pthread_atfork}, nor does it reset
326 any internal state or locks (such as the @code{malloc} locks). In the
328 @code{dup2} or @code{execve}.
330 The @code{_Fork} function is an async-signal-safe replacement of @code{fork}.
340 The @code{vfork} function is similar to @code{fork} but on some systems
344 While @code{fork} makes a complete copy of the calling process's address
346 @code{vfork} does not make this copy. Instead, the child process
347 created with @code{vfork} shares its parent's address space until it
348 calls @code{_exit} or one of the @code{exec} functions. In the
352 @code{vfork} to modify any global data or even local variables shared
354 do a long jump out of) the function that called @code{vfork}! This
356 in doubt, use @code{fork} instead.
358 Some operating systems don't really implement @code{vfork}. @Theglibc{}
359 permits you to use @code{vfork} on all systems, but actually
360 executes @code{fork} if @code{vfork} isn't available. If you follow
361 the proper precautions for using @code{vfork}, your program will still
362 work even if the system uses @code{fork} instead.
368 @cindex @code{exec} functions
370 This section describes the @code{exec} family of functions, for executing
374 To see the effects of @code{exec} from the point of view of the called
385 The @code{execv} function executes the file named by @var{filename} as a
389 used to provide a value for the @code{argv} argument to the @code{main}
396 @code{environ} variable of the current process image; see
403 This is similar to @code{execv}, but the @var{argv} strings are
411 This is similar to @code{execv}, but permits you to specify the environment
413 be an array of strings in the same format as for the @code{environ}
420 This is similar to @code{execve}, but instead of identifying the program
422 descriptor must have been opened with the @code{O_RDONLY} flag or (on
423 Linux) the @code{O_PATH} flag.
425 On Linux, @code{fexecve} can fail with an error of @code{ENOSYS} if
427 underlying @code{execveat} system call.
433 This is similar to @code{execl}, but permits you to specify the
437 the @code{environ} variable.
443 The @code{execvp} function is similar to @code{execv}, except that it
444 searches the directories listed in the @code{PATH} environment variable
456 This function is like @code{execl}, except that it performs the same
457 file name searching as the @code{execvp} function.
461 not be greater than @code{ARG_MAX} bytes. @xref{General Limits}. On
462 @gnuhurdsystems{}, the size (which compares against @code{ARG_MAX})
464 the size of a @code{char *}, plus one, rounded up to a multiple of the
465 size of a @code{char *}. Other systems may have somewhat different
470 of @code{-1} is returned in the event of a failure. In addition to the
472 @code{errno} error conditions are defined for these functions:
474 @table @code
477 list is larger than @code{ARG_MAX} bytes. @gnuhurdsystems{} have no
478 specific limit on the argument list size, so this error code cannot
479 result, but you may get @code{ENOMEM} instead if the arguments are too
545 new process image, unless they have the @code{FD_CLOEXEC}
550 Streams, by contrast, cannot survive through @code{exec} functions,
553 the streams in the pre-@code{exec} process image has a descriptor inside
554 it, and these descriptors do survive through @code{exec} (provided that
555 they do not have @code{FD_CLOEXEC} set). The new process image can
556 reconnect these to new streams using @code{fdopen} (@pxref{Descriptors
573 The @code{waitpid} function is used to request status information from a
579 value of @code{-1} or @code{WAIT_ANY} requests status information for
580 any child process; a value of @code{0} or @code{WAIT_MYPGRP} requests
590 from the other eligible child processes, you need to call @code{waitpid}
595 @code{WNOHANG} and @code{WUNTRACED} flags. You can use the
596 @code{WNOHANG} flag to indicate that the parent process shouldn't wait;
597 and the @code{WUNTRACED} flag to request status information from stopped
605 descriptors, semaphores or whatever) at the time @code{waitpid} is
607 until the program ends. To avoid this calls to @code{waitpid} should be
613 waiting to be noticed, @code{waitpid} will block until one is. However,
614 if the @code{WNOHANG} option was specified, @code{waitpid} will return
617 If a specific PID to wait for was given to @code{waitpid}, it will
620 of them, @code{waitpid} will block or return zero as described above.
622 A value of @code{-1} is returned in case of error. The following
623 @code{errno} error conditions are defined for this function:
625 @table @code
640 to the @code{waitpid} function.
643 @vtable @code
646 This constant macro (whose value is @code{-1}) specifies that
647 @code{waitpid} should return status information about any child process.
651 This constant (with value @code{0}) specifies that @code{waitpid} should
657 argument to the @code{waitpid} function. You can bitwise-OR the flags
660 @vtable @code
663 This flag specifies that @code{waitpid} should return immediately
668 This flag specifies that @code{waitpid} should report the status of any
676 This is a simplified version of @code{waitpid}, and is used to wait
692 descriptors, semaphores or whatever) at the time @code{wait} is
694 until the program ends. To avoid this calls to @code{wait} should be
702 If @var{usage} is a null pointer, @code{wait4} is equivalent to
703 @code{waitpid (@var{pid}, @var{status-ptr}, @var{options})}.
705 If @var{usage} is not null, @code{wait4} stores usage figures for the
706 child process in @code{*@var{rusage}} (but only if the child has
712 Here's an example of how to use @code{waitpid} to get the status from
714 function is designed to be a handler for @code{SIGCHLD}, the signal that
745 process is zero, then the status value reported by @code{waitpid} or
746 @code{wait} is also zero. You can test for other kinds of information
755 normally with @code{exit} or @code{_exit}.
761 If @code{WIFEXITED} is true of @var{status}, this macro returns the
777 If @code{WIFSIGNALED} is true of @var{status}, this macro returns the
797 If @code{WIFSTOPPED} is true of @var{status}, this macro returns the
805 @Theglibc{} also provides the @code{wait3} function for compatibility
807 predecessor to @code{wait4}, which is more flexible. @code{wait3} is
814 If @var{usage} is a null pointer, @code{wait3} is equivalent to
815 @code{waitpid (-1, @var{status-ptr}, @var{options})}.
817 If @var{usage} is not null, @code{wait3} stores usage figures for the
818 child process in @code{*@var{rusage}} (but only if the child has
826 similar to the built-in @code{system}. It executes its @var{command}
870 Remember that the first @code{argv} argument supplied to the program
872 call to @code{execl}, @code{SHELL} is supplied once to name the program
873 to execute and a second time to supply a value for @code{argv[0]}.
875 The @code{execl} call in the child process doesn't return if it is
877 process terminate. Just returning a bad status code with @code{return}
882 Call @code{_exit} to accomplish this. The reason for using @code{_exit}
883 instead of @code{exit} is to avoid flushing fully buffered streams such
884 as @code{stdout}. The buffers of these streams probably contain data
885 that was copied from the parent process by the @code{fork}, data that
886 will be output eventually by the parent process. Calling @code{exit} in