From Surf Wiki (app.surf) — the open knowledge base
C process control
Functions of the C standard software library
Functions of the C standard software library
C process control refers to a group of functions in the standard library of the C programming language implementing basic process control operations. 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
The process control functions are defined in the stdlib.h header (cstdlib header in C++).
| Function | Description | Terminating | |
|---|---|---|---|
| a program | Communicating with | ||
| the environment | |||
| abort`abort` | causes abnormal program termination (without cleaning up) | ||
| exit`exit` | causes normal program termination with cleaning up | ||
| _Exit`_Exit` | causes normal program termination without cleaning up (C99) | ||
| atexit`atexit` | registers a function to be called on exit() invocation | ||
| quick_exit`quick_exit` | causes normal program termination without cleaning up, but with IO buffers flushed (C11) | ||
| quick_exit`at_quick_exit` | registers a function to be called on quick_exit() invocation | ||
| getenv`getenv` | accesses the list of the environment variables | ||
| system`system` | calls the host environment's command processor |
Example
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
References
- Crawford, Tony. (December 2005). "C in a Nutshell". O'Reilly.
- "ISO/IEC 9899:1999 specification".
This article was imported from Wikipedia and is available under the Creative Commons Attribution-ShareAlike 4.0 License. Content has been adapted to SurfDoc format. Original contributors can be found on the article history page.
Ask Mako anything about C process control — get instant answers, deeper analysis, and related topics.
Research with MakoFree with your Surf account
Create a free account to save articles, ask Mako questions, and organize your research.
Sign up freeThis content may have been generated or modified by AI. CloudSurf Software LLC is not responsible for the accuracy, completeness, or reliability of AI-generated content. Always verify important information from primary sources.
Report