Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to call common functions in Linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article shows you how to call common functions in Linux, which is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Common function calls in Linux

I. create a process

Create a summary of the process:

1. The parent process in Linux calls fork to create the child process.

2. When the parent process calls fork, the child process copies the data interface and code of all the parent processes.

3. The current process is a child process, and fork returns 0; the current process is the parent process, and fork returns the child process number

4. If 0 is returned, the current process is a child process, and the child process requests the execve system call to execute another program.

5. If the child process number is returned, it indicates that the current process is the parent process and executes according to the original plan of the parent process.

6. The parent process is responsible for the child process. Call waitpid to take the child process number as a parameter, and the parent process will know whether the child process has finished running and whether it is successful or not.

7. When the operating system starts, a "ancestor process" of all user processes is created. Class hour 1, question 3 option A: process 0 is the ancestor of all user-mode processes.

System call to create a process: fork executes a system call to another program: execve passes the process number of the child process as a parameter, and the parent process will know whether the child process has finished running, whether it is successful or not: waitpid

II. Memory management

Memory management summary

1. Each process has its own process memory space, which does not interfere with each other. (isolation)

2. The process memory space, the part where the program code is stored, is called code segment (Code Segment).

3. The part that stores the data generated during the operation of the process is called the Data Segment.

4. When the process writes data, the current physical memory is allocated to the process.

5. If the amount of memory allocated is relatively small, the brk call will be connected with the original heap data.

6. When the amount of memory data that needs to be allocated is relatively large, use mmap to repartition a memory area.

Allocate a smaller amount of memory and connect it with the original heap data: brk allocates a larger amount of memory and redivides a memory area: mmap

III. Document management

File operation six most important system calls: open file: open close file: close create file: creat open file and jump to a location of the file: lseek read file: read write file: writeLinux everything is a file, even if it unifies the entry of the operation, it provides great convenience.

Signal processing (exception handling)

Once there is a change in the execution of the process, it can be processed in time through the signal processing service.

V. Inter-process communication

There are two ways to implement interprocess communication message queuing to create a new queue: msgget sends messages to message queues: msgsnd fetches messages from the queue: msgrcv

VI. Shared memory mode

Create a shared memory block: shmget maps shared memory to its own memory space: shmat uses semaphores to isolate occupancy semaphores: sem_wait release semaphores: sem_post

Pseudocode: suppose the semaphore is 1 signal = 1 sem_wait pseudocode while True {if sem_wait = = 1; signal-= 1; break;} code.code; sem_post pseudocode signal + = 1

VII. Network communication

Network socket: socket network communication follows TCP/IP network protocol stack

VIII. Glibc

Glibc is the open source standard C library under Linux glibc further sealed the system calls sys_open corresponding to the open function of glibc a single glibcAPI may call multiple system calls printf functions call sys_open, sys_mmap, sys_write, sys_close and other system calls the above is how to call common functions in Linux, have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report