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:
- The processes triggered by these jobs must come from your shell's child processes (just manage your own bash);
- Foreground: You can control the work of the environment called foreground (foreground) with the placing of directives;
- Background: You can work on your own, you cannot use [ctrl]+c to terminate him, you can use BG/FG to call the job;
- The "executing" process in the background cannot wait for the input of the Terminal/shell
Management method:
- Drop the instruction directly into the background of "execute" &
- Drop "current" work into the background "pause": Ctrl + Z
- Observe current background work status: Jobs [-lrs]
- Get background work to the foreground: FG%jobnumber
- 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