Communication with the Operating System
- Environment
In operating systems such as Unix and Windows, each process is started in an environment represented by a list of strings with the form
NAME=VALUE. These “environment variables” can be read using the functiongetenv().- System calls
The function
system()invokes the system’s command interpreter and gives it a command to execute.- Program termination
A C program is normally terminated via a call to the function
exit(), or by areturnstatement in the functionmain(). On normal termination, the following actions are performed:Any functions that have been installed by
atexit()are executed.The I/O buffers are flushed and the files closed.
The files created by
tmpfile()are deleted.
The function
abort(), on the other hand, ends a C program without performing the actions just listed. This function does produce an error message announcing that the program was aborted, however.The function
exit()can be called with one of the constantsEXIT_FAILUREandEXIT_SUCCESS, defined in stdlib.h, as an argument. In this way the program can inform its parent process whether it “failed” or “succeeded.”
All of the functions described in this section are declared in the header file stdlib.h.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access