Linux Multi-process multithreading related concepts

Source: Internet
Author: User
Tags session id

process : An executable is a static entity that is stored on a disk device by code and data that is organized in a format, while a process is dynamically run by the code that can be dispatched. In a Linux system, each process has its own life cycle. In the life cycle of a process, there are individual operating environments and the required resources, which are recorded in the respective process control blocks so that the system can effectively manage these processes, as shown in the structure of the Process Control block:

Each process has its own independent virtual address space, and the size of the space is related to the hardware architecture on which it is based. The meaning of each area in the virtual space, the code snippet stores instruction sequences and read-only data, and multiple process instances can share code snippets. Data segments are used to hold global variables and static variables. The heap area is used for dynamic memory management of programs, and new or malloc requests memory is located in the heap. The stack is used to store local variables in the process, function returns address, parameters, and process context.

Threads : The introduction of a process is to solve the problem of concurrent execution of the program, and the introduction of the thread is to reduce the time and space costs of the program concurrency, the thread is smaller than the process of the unit, a process has at least one thread, the thread is the operating system to dispatch the basic unit, Threads do not consume system resources at all, and threads share the resources that the process occupies with other threads that are part of a process.

Application programming interfaces (related header files and parameter types can be viewed through the man command)

Process Environment 

Getuid get the actual user ID of the current process

Geteuid obtaining the current process valid user ID

Getgid get the actual user group ID of the current process

Getegid get the current process valid user group ID

Getpid get current Process ID

Getppid Get parent Process ID

GETPGRP Get process Group ID

Setpgid set up a process group

GetSID getting the process session ID

Setsid setting the process session ID

Process address space

malloc Request Memory

Free memory

BRK Setting the heap area size

Creation and termination of processes

Fork Create Child process

Exit Terminate Process

Atexit Registration Termination Handler

Loading an executable binary image

Exec

Synchronization control of the process

Wait pauses execution until a child process ends

Waitpid waiting for the specified child process to end

Thread

1. Pthread_equal//Determine if thread is the same
2. Pthread_self//Returns the ID of the calling thread
3. Pthread_create//Create thread
4. Pthread_exit//Exit thread
5. Pthread_join//Start thread
6. Pthread_cancel//Cancel Thread
7. Pthread_cleanup_push
8. Pthread_cleanup_pop
9. Pthread_detach
Ten. Pthread_mutex_init
Pthread_mutex_destroy.

Summary : This section briefly describes the concepts of Linux under multi-process and multithreading, and introduces some of the APIs used in programming, as well as examples of multi-process programming and multithreaded programming are described in the next section.

Linux Multi-process multithreading related concepts

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.