Chapter 12th Process Management

Source: Internet
Author: User

first, the process

1. Overview of the process

A program is an executable file, and a process is a dynamic process of executing a program. A process is an entity that provides the execution environment for a running program, including an address space and a control point.

When executing a program, the system loader loads the program into memory, which consists of 5 parts in memory: body, initialization data, uninitialized data, stack, user area

A process typically consists of three main parts: code, data, Process Control block (PCB). The code section describes what the process is going to do, and the data section includes the data and workspace that the program needs to execute. The code part and the data part of the process are the material basis for the process to exist. The Process Control block (PCB) includes the process description information and control information, which is a centralized reflection of the dynamic process, and the system sets up a process control block for each process. A Process Control block is a unique identifier for the existence of a process.

In UNIX systems, the Process control block consists of two parts: one is the basic control block of the process, becomes the proc structure, and the other part is the process expansion control block, called the user structure. These two parts can describe a process entity in its entirety. What is stored in the proc structure is the information necessary for the system to determine the existence of a process, and the user structure is the information that the process needs to use at runtime. It can be said that all processes have the same proc structure, and that the user structure of all processes differs depending on the process. Process proc Structure resident memory, regardless of whether the process is running on the machine, the core of the system to query and determine the proc structure of any process, the user structure of the process is not resident memory, when the entry is not running on the processing machine, the system core does not query and processing this part of the information, So when the process is not running, the user structure is written to the external memory switching device.

The process of the derived process becomes the parent process, the derived process becomes a child process, a process has only one parent process, and a process can have more than one child process.

2. Process scheduling Status

1) Operating Status:

2) Ready state:

3) Blocking Status:

The number of processes running in a system must be less than or equal to the number of available processors, because a processor can execute only one process code at a time.

When a process is switched from a running state to a blocking state for some reason or when it consumes the processor's time slice, the process scheduler selects a process from the ready queue that has the highest priority, allowing it to occupy the processor and run it. The state transition of a process is done by the process scheduler.

is: the basic scheduling state and conversion of the process

In addition, in AIX systems, the process scheduling state is also divided into 6 types: nonexistent State (noexistent), running State (active), switched state (swapped), Idle State (idle), cancellation State (Cancelled), and stop State (Stopped)

3. Process characteristics

1) concurrency; several processes exist in the system at the same time

2) Dynamic: The process has a life cycle, dynamic production and extinction

3) Independence; Refers to the process before the emergence of a process as a unit capable of running independently, is the system of resource allocation and scheduling of the basic unit

4. Parent and child processes

Some processes in the system are born when the system is powered on, until the system shuts down, and this process is generally referred to as the system process.

Any process must have a parent process, the parent process dies, the child process will inevitably die, but the user can manually set the intervention, so that the child process lost the parent process by the system's most primitive process (the init process, the process number is 1) adopted, as its "child process"-- The human intervention method is to add the nohup command before the command, then the child process can be taken over by the Init process after the parent process dies, and thus continue to exist.

The shell environment variable is valid only for the current process, and when an environment variable is set, it is valid for all subsequent child processes that it produces.

5, the system process system

When the AIX system is booted, a swapper process is automatically created, its process number is 0, the ancestor of all processes, the process of scheduling the system process, and then the process of creating an init process by the process number No. 0, which is the 1,init process reads the file at system startup/etc/ Inittab, and then creates the relevant process to complete the corresponding system startup work based on each line of content. In addition to creating the init process, the swapper process creates processes that are related to the core of the system. In Aix 5L systems, the core process name of the system identifies the purpose of the process, and the main core processes are: Wait, Reaper, XMGC, Netm, Gil, wlmsched, LVMBB, Rtcmd, and Kbiod

Most of the processes in the system are created by the INIT process or the child process of the INIT process, so that generations, when a process loses the parent process, and the system has set the Nohup parameter, it will be directly taken over by the INIT process.

Once the system is in a multi-user state, the INIT process generates a Getty process for each user terminal, which is monitored by the Getty process so that the user can log on to the system. After the user login succeeds, the Getty process dies, and the user's shell process is replaced.

in the system to open up a large space for all the process information in the system, this is the process table, there is also a large area to store thread information, called the thread table, yourselves thread table must be much larger than the process table.

6. Foreground process and background process

The foreground process occupies a terminal at run time and can be interfered with by the user, and if the process is running, the user can run other commands without affecting its operation, which is called a background process. The process of a service class is typically run in the background. If a process does not need keyboard input when it is running and adds a spoof "&" symbol after the command is entered, then he becomes a background process.

7. Zombie Process

After the death of the process, if its corpse has not been revoked, the process table retains its record (also said it still has the process number), the dead, the body remains in the process table process is a zombie process.

The corpse in the process table is the resource that the zombie process consumes, and the child process does not release the resources it occupies, and the child process keeps its body in the process table until its parent process dies or the system restarts.

Zombie process and orphan process is different, the zombie process is already dead process, no longer run, but it still occupies the system resources, so the zombie process is a waste of system resources, the orphan process is to go to the biological parent process, was adopted by the INIT process, it is still running, so the orphan process does not waste system resources. Only the zombie process can affect system efficiency.

8. Daemon Process

The daemon process is a process that never stops, it often runs in the background and most of the time is idle, and the daemon process usually starts or runs when the system boots, until the system shuts down.

The process of controlling the system resources is the daemon process, the daemon process is not related to the terminal and the user, so when using the PS command, it will show one? No.

The following are some of the daemon processes in the AIX system:

Init:pid is 1, the first process created after the system starts, it is the ancestor of all non-system processes

Kproc: The core process of the system

Corn: Automatic scheduling of job runs

Qdaemon: Controlling the job time queue process

SRCMSTR: System Resource Controller process

INETD: Network port monitor process

SendMail: E-mail management process

Errdaemon: Error log process

SYSLOGD: System Logging Process

DTLOGIN:CDE Server process

second, the thread

The purpose of using process mechanism in UNIX system is to improve system efficiency and system resource utilization. In multi-tasking system, the process is executed concurrently on the processing machine, which is not only the basic unit of system dispatch , but also the basic unit of system resource allocation. Process throughout the life cycle, constantly change the operating environment, constantly changing the state, in the process of switching, because it is necessary to save the current process of the running environment, but also set the running environment of the selected process, it takes a lot of processor time

Therefore, in the operating system that introduces the thread, the thread is the basic unit of the system dispatch , but not the basic unit of allocating the resources independently, so it does not implement the frequent switching of the basic unit that owns the resource. A thread is a scheduled entity within a process and is an execution unit within a process. The basic unit of the processor dispatch is no longer a city, but a thread.

The relationship between processes and threads is summarized as follows:

1) threads are part of a process, and each process is created with only one thread, which can create multiple threads when needed

2) The multithreading of a process is active within the address space of the process, and the thread's active scope is always confined to the inside of the process.

3) Resources are still allocated on a process-by-unit, rather than county-based units, and the threads are deducted from the resource quotas of the process and assigned to them when they need resources at execution time.

4) The basic unit of processor scheduling is a thread, the thread will compete between the processor, the actual processing machine is running a thread, the same between the various threads also have priority. The AIX system supports SMP (symmetric multi-processing) operating mode, which allows for reasonable load balancing between the various CPUs in the system.

third, Process Control

Processes are produced in two ways, one from the user executing the command, and the other by the fork process. The user knows to execute a command, first this command (or script) to have execute permission--by #chmod +x [name] to the script to increase the execution permissions

1, Nohup

The shell provides an operator &, which allows the user to run the program in the background. Add the nohup command before the command. Then when the user exits the system (note that the user exits the system, not the system shutdown), all processes generated by the shell receive a termination signal of 01 and 03, and the Nohup command actually tells the shell that the background process is ignoring this two signal, allowing it to continue executing.

When a pipe symbol (|) is used in the background and requires the Nohup function, the two commands before and after the pipe character are rendered using the Nohup parameter respectively.

#nohup Ls-r | nohup grep DT >/tmp/lsdt.out&

Because the background process initiated by the NOHUP command cannot display its output to the terminal, if the user does not redirect its output structure, the nohup command redirects the output of the background process to the Nohup.out file. If multiple background processes are started in the same directory by the Nohup command, and the output is not redirected, then the Nohup.out file will be overwritten continuously, causing some output to be lost.

Because all processes need to have a parent process associated with it, when the user exits the system, the NOHUP process is taken over by the INIT process.

2. Process Priority

The higher the value of Nice, the lower the priority, while the nice value ranges from 0 to 39,nice with a value of 39, with the lowest priority. Front desk Nice The default value is 20. The background process default value is 24, and the child process inherits the Nice value of the parent process.

The user can change the priority of the process by changing the nice value of the process. The command to change the priority of the process is as follows:

#nice [-N Increment] Command [Argument ...]

Where the value of increment is positive take negative, only the root user can go negative, negative value is to increase the priority, positive value is to reduce the priority, if not add-n increment parameter. The default is to add a nice value of 10 points (that is, lower the priority).

The nice command only determines the nice value of the process when the process is started and cannot modify the nice value of the process while the process is running, while the Renice

command to implement this function.

#renice [-N Increment] [-G |-P |-u] ID ...

Where the-g parameter is used to change the priority of all processes in a process group, the ID is represented as the number of the process group, the priority of the specified process is changed with the-p parameter, the ID is the process number, the-p parameter is the default, and the-u parameter changes the priority of all processes that belong to the user, It can also be a user ID. Where IDs can be specified more than one, they are separated by a space.

If the Renice return code is 0, it indicates that the modification of Nice succeeds, otherwise, an error occurs.

3. Kill Process

#kill [-S {signalname | Singalnumber}] ProcessID ...

Where ProcessID is the process ID that receives the signal, and Signalname is the signal name (in the form of a string), Signalnumber is the signal designator (positive integer form). Kill command If you do not specify Signalname and Signalnumber, the default is to send a termination signal (SIGNALNUMBER=15).

Signalnumber=0,kill command to check whether the specified ProcessID is valid;

Signalnumber=9, kill process Signal (SIGKILL);

SIGNALNUMBER=15, terminating the process signal (SIGTERM). 15 signal strength is not 9 strong, 15 can not kill 9 kill lost.

Processid>0, which indicates the process of sending the signal to the specified ProcessID;

Processid=0, indicating that the signal is sent to all processes that are identical to the sender Pgid;

Processid=-1, sending signals to all processes that are identical to the sender's active user;

Processid<1&processid<>1, indicating that all processes that send the signal to "equal absolute value of Pgid and ProcessID"

Iv. core files in AIX 5L

When the process terminates abnormally, the system writes the data in the address space corresponding to the process into the core file, and the whole process becomes dump. All of the core files in the AIX4.3.3 are core,aix5l, changing the core command so that each core has a unique name that prevents the possibility of being overwritten.

AIX5L the core_naming environment variable is set, the new core file name format is CORE.PID.DDHHMMSS such a format.

(Note that the predefined value of the core_naming environment variable is yes, so it doesn't matter whether you give the variable a value or even give him a no value, the system starts the new CORE naming method)

Each core dump generates a new error log, and viewing such error logging can help programmers identify the application that caused the core dump.

AIX5L enhanced the Automatic collection of core files, the role of the Snapcore command is the phone a core file, program, uh, a library of programs, and then compress the data into a pax file

Chapter 12th Process Management

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.