APUE Process Environment

Source: Internet
Author: User

Basic environment of the process

1. Main function prototype

int main (int argc, char *argv[]);

Before the EXEC function executes the main function, call a special startup routine and change the start routine to the starting address of the program.

The goal is to get the command-line arguments and environment variables for the process from the kernel

2. Termination of the process

There are many ways to terminate a process, often with

(1) Return from main

Return is actually called the Exit function.

The Exit function performs a clean shutdown of the standard I/O library, fclose all open streams, and flush the modified data.

(2) Abort

(3) Call the Exit function

(4) Receiving the signal

...

3. Command line Parameters

ARGC is the number of command-line arguments, argv is the command-line array. The array size is argc+1 and the last value is null

4. Environment table

The global variable environ points to the starting address of the environment table, which is an array of strings that hold the C string in name=value form.

5, c program storage space layout


The body segment can be shared, read-only, and prevented from being modified. The BSS segment is not stored in the disk program file because the variables of that segment are initialized to 0 or null by the EXEC function.

The body segment and the initialized data are stored in the disk program file.

command-line arguments and environment variables are stored in the highest address space, and their modifications are cumbersome because space is limited. Sometimes you need to reapply for space, or copy space.

6. Shared Library

The shared library is actually the intermediate file that has been compiled, in binary form. The shared library makes it unnecessary to include functions in the executable file that need to be common, simply referencing the functions of the shared library.

The advantage of invoking a dynamic library is that it can reduce the size of the executable file, updating the library without modifying the source program, and the downside is increasing the runtime overhead when the program first executes or when the shared library is first called.

The-static parameter specifies that the static library is called, and the dynamic shared library is called without adding

Size command to see the sizes of each field in the program

APUE Process Environment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.