Linux Process Management

Source: Internet
Author: User
Tags network function

Overview

  function of kernel: process Management, file system, network function, memory management, driver, security function

  process-Related: process creation (FORK-EXEC)--Process priority (PRI (0-139), Nice)--process memory (Page frame)-->IPC (Inter process Communication)--process type (daemon, user process)--process status--process classification (Cpu-bound,io-bound)

  process viewing and management tools:Pstree, PS, Pidof, Pgrep, Top, htop, glance, Pmap, Vmstat, Dstat, Kill, Pkill, job, BG, FG, Nohup,lsof, Fuser

1. Processes and Procedures

Program:

Usually binary program, placed in the storage media (such as hard disk, CD-ROM, floppy disk, tape, etc.), the form of the entity file exists;

Progress (Process):

After the program is triggered, the performer's permissions and properties, program code and required data will be loaded in memory, the operating system and give the memory unit an identifier (PID), it can be said that the process is a running program.

We know that we log on to the Linux system is the implementation of the/bin/bash, and then the system according to Uid/gid (/ETC/PASSWD) to assign us a PID, and then the process derived from the other processes in the general state, will also follow the relevant permissions of the process! This is why Linux can create an independent environment for each user. The moment you log in to your system, you decide what permissions to operate.

2. Parent and child processes

  fork-and-exec:a process in a Linux system produces an identical child process by copying (fork) The parent process, and then the copied child process executes the actual program in an exec manner, and eventually becomes the existence of a child process.

Example:

PS: the first bash PID and the second bash's PPID are 2197, because the second bash comes from the first one!

3. Work Management

When we log on to a Linux system, it means that each of our next work is a child of the current bash, which is related to each other. We can't manage Tty2 bash in the tty1 environment by job Control!

Under what circumstances do you use job control:

    1. The processes triggered by these jobs must come from your shell's child processes (just manage your own bash);
    2. Foreground: You can control the work of the environment called foreground (foreground) with the placing of directives;
    3. Background: You can work on your own, you cannot use [ctrl]+c to terminate him, you can use BG/FG to call the job;
    4. The "executing" process in the background cannot wait for the input of the Terminal/shell

Management method:

    1. Drop the instruction directly into the background of "execute" &
    2. Drop "current" work into the background "pause": Ctrl + Z
    3. Observe current background work status: Jobs [-lrs]
    4. Get background work to the foreground: FG%jobnumber
    5. Let the work in the background state become operational: BG%jobnumber
Offline management (Nohup [] &)

Example:

#!/bin/Bash/bin/Sleep500s/bin/Echo "I have slept seconds."...... [Email protected] test]#chmodA+x sleep500s.SH[email protected] test]# nohup./sleep500s.SH&[1]2733[email protected] test]# nohup:ignoring input and appending output to ' nohup.out '[email protected] test]# exitlogout

After exiting the current TTY, log in again and view through Pstree (./sleep500s.sh &)

[[Email protected] ~]# Pstreeinit─┬─abrtd├─acpid├─atd├─auditd───{auditd}├─console-kit-dae─── the*[{console-kit-da}] ├─crond├─dbus-Daemon├─hald─┬─hald-runner─┬─hald-addon-Acpi││├─hald-addon-Inpu││└─hald-addon-rfki│└─{hald}├─Login───bash├─master─┬─pickup│└─qmgr├─5*[mingetty]├─rsyslogd───3*[{rsyslogd}] ├─sleep500s. Sh───sleep├─sshd───sshd───bash───pstree└─udevd───2*[ UDEVD] [[email protected] test]#ls nohup.out sleep500s.SH

PS: since our program will eventually output a message, but the nohup is not related to the terminal, so the output of this message will be directed "~/nohup.out"

Linux 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.