C process control refers to a group of functions in the standard library of the C programming language implementing basic process control operations.[1][2] The process control operations include actions such as termination of the program with various levels of cleanup, running an external command interpreter or accessing the list of the environment operations.

Overview of functions

edit

The process control functions are defined in the stdlib.h header (cstdlib header in C++).

Function Description
Terminating
a program
abort causes abnormal program termination (without cleaning up)
exit causes normal program termination with cleaning up
_Exit causes normal program termination without cleaning up (C99)
atexit registers a function to be called on exit() invocation
quick_exit causes normal program termination without cleaning up, but with IO buffers flushed (C11)
at_quick_exit registers a function to be called on quick_exit() invocation
Communicating with
the environment
getenv accesses the list of the environment variables
system calls the host environment's command processor

Example

edit

The following is an example of communicating with the system environment in C.

#include <stdio.h>
#include <stdlib.h>

int main() {
    char* path = getenv("PATH");
    if (!path) {
        fprintf(stderr, "PATH environment variable not found.\n");
    } else {
        printf("PATH variable: %s\n", path);
    }

    printf("Listing current directory contents using system(\"ls\"):\n");
    int ret = system("ls");

    if (ret == -1) {
        fprintf(stderr, "system() call failed!");
    }

    return 0;
}

References

edit
  1. ^ Crawford, Tony; Peter Prinz (December 2005). C in a Nutshell. §16.11 – Process Control: O'Reilly. p. 618. ISBN 0-596-00697-7.{{cite book}}: CS1 maint: location (link)
  2. ^ ISO/IEC 9899:1999 specification (PDF). p. 315, § 7.20.4 "Communication with the environment". Retrieved 25 November 2011.
edit

📚 Artikel Terkait di Wikipedia

PHP

An example of the early PHP syntax: <!--include /text/header.html--> <!--getenv HTTP_USER_AGENT--> <!--if substr $exec_result Mozilla--> Hey, you are using

Common Gateway Interface

saying that environment variables "are accessed by the C library routine getenv() or variable environ". The name CGI comes from the early days of the Web

Version 7 Unix

available), umask, utime New library calls: The new stdio routines, malloc, getenv, popen/system Environment variables A maximum file size of just over one

AWK

environment variable; its result is the variable's value. This is like the getenv function in various standard libraries and POSIX. The shell script makes

Scsh

(newline)) (for-each writeln (append-map executables ((infix-splitter ":") (getenv "PATH")))) The reference manual for Scsh includes a spoof Acknowledgments

AmigaDOS

variables can be set using the command Set. There are also the commands GetEnv and Get that can be used to print out global and local variables. The examples

Entry point

argument giving the program's environment, otherwise accessible through getenv() in <stdlib.h>: int main(int argc, char* argv[], char* envp[]); Darwin-based

Racket features

60 4) 15) 60)) ; wait 3h 45m (send-mail-message (getenv "EMAIL") "Parking meter alert!" (list (getenv "EMAIL")) null null '("Time to go out and move the