Management process of linux basic commands

Source: Internet
Author: User
Tags pkill
I. linux boot process (first, let's take a look at the linux boot Guide process) boot self-check MBR boot (masterbootrecord master boot record) GRUB Menu (if multiple systems are used, which system is used to choose to use) load the Linux kernel INIT process to initialize the init process... i. linux boot Guide process (first, let's take a look at the linux boot Guide process)
 
Boot self-check
MBR boot record)
GRUB Menu (if multiple systems are used, select which system to use)
Load Linux kernel
INIT process initialization
Init process
---- It is the parent process of all processes and the corresponding PID is 1./sbin/init is the first program to be loaded in the kernel. it cannot be easily terminated. the configuration file is/etc/inittab!
 
Inittab configuration file
---- The inittab file is located in the/etc directory. after the init process runs, the scripts and programs to be run in the system are started according to the configuration in the file.
 
Example: view the valid configuration lines in the/etc/inittab File (remove comment lines and empty lines)
 
[Root @ localhost ~ ] # Grep-v "^ #"/etc/inittab | grep-v "^ $" (-v reverse query)
Id: 3: initdefault :( get this result, 3 refers to start from the character interface)
 
The structure of the result is as follows:
Mark: running level: action type: program or script
 
Id -- mark a field
Runlevels -- running level field
Action -- action type field
Process -- program or script field
 
There are seven running levels:
 
0: shutdown status
1: Single-user mode, login without a password, mostly used to maintain the system
2: Multi-user mode on the character interface (network not supported)
3: full multi-user mode on the character interface
4: Unused
5. Gui multi-user mode
6: Restart
Note: different runtime-level code combinations, such as 2345, indicate that the configuration is valid when it enters Level 2, Level 3, Level 4, and level 5.
 
For example, check the default running level of the current system and change the default level to 3 so that the system will automatically enter the text mode after the next boot.
[Root @ localhost ~ ] # Grep ": initdefault"/etc/inittab
Id: 5: initdefault: (at this moment, the default level is 5, which will be started from the graphic interface)
......
[Root @ localhost ~ ] # Vi/etc/inittab
Id: 3: initdefault: (change 5 to 3)
......
 
For example, you can view the operation corresponding to Ctrl + Alt + Delete set in the inittab File (restart after 3 seconds). If you add the "#" sign before the row record, you can disable this function.
[Root @ localhost ~ ] # Grep ": ctrlaltdel"/etc/inittab
Ca: ctrlaltdel:/sbin/shutdown-t3-r now
 
For example, confirm the configuration of each row in the inittab file using the "respawn" operation.
[Root @ localhost ~ ] # Grep ": respawn"/etc/inittab
1: 2345: respawn:/sbin/mingetty tty1
2: 2345: respaws:/sbin/mingetty tty2
......
6: 2345: respaws:/sbin/mingetty tty6
X: 5: respawn:/etc/Xll/preofdm-nodaemon
 
Rc. sysinit script file
-- Is the system initialization script called by the init process. in/etc/rc. d/rc. sysinit, the script mainly includes setting the network, host name, loading the file system, and setting the clock.
 
For example, check the initialization script file used in the current linux system, confirm the file type, and view the content of the first 10 lines.
[Root @ localhost ~ ] # Grep ": sysinit"/etc/inittab
Si: sysinit:/etc/rc. d/rc. sysinit
[Root @ localhost ~ ] # File/etc/rc. d/rc. sysinit
/Etc/rc. d/rc. sysinit: Bourne-Again shell script text executable
[Root @ localhost ~ ] # Head-10/etc/rc. d/rc. sysinit
#! /Bin/bash
#
#/Etc/rc. d/rc. sysinit-run once at boot time
#
......
HOSTNAME = '/bin/hostname'
HOSTTYPE = 'uname-M'
Unamer = 'uname-R'
 
Rc script file
-- It is also called by the init process. It is located at/etc/rc. d/rc, and different system services are loaded and terminated by setting parameters of different levels!
 
For example, disable the cups printing service.
[Root @ localhost ~ ] # Service cups stop or run/etc/rc. d/init. d/cups stop
For example, restart the network service.
[Root @ localhost ~ ] # Service network restart or run/etc/rc. d/init. d/network restart
 
Rc. local script file
-- An additional startup control file located in/etc/rc. d/rc. local, usually the final execution, role: The administrator sets the path for providing self-startup commands, and files that need to be self-started can be placed in it
 
For example, check that the rc. local script file is loaded at the location of the rc. local script file and at each running level.
[Root @ localhost ~ ] # Ls-l/etc/rc. d/rc ?. D/* local/etc/rc. d/rc. local
 
For example, add a command to the rc. local script to automatically proofread the system time based on the clock in the BIOS after each startup.
[Root @ localhost ~ ] # Vi/etc/rc. d/rc. local
/Sbin/hwclock -- hctosys
 
Operation level control
 
View the system running level -- [root @ localhost ~ ] # Runlevel
Switch system running level -- init 3 (switch to character interface) init 0 (shutdown)
 
Set the status of system services at different running levels
 
1. use ntsysv configuration tool (* indicates automatic start, no vice versa)
Directly use ntsysv for the current running level only. you can use -- level to specify the running level.
 
2. chkconfig configuration tool
[Root @ localhost ~ ] # Chkconfig -- list network (view the status of the network service at the current running level, if no specific service is specified, display all)
[Root @ localhost ~ ] # Chkconfig -- level 35 network on or off (specify the status of the network service in the 3 or 5 running level on or off)
 
Process Management
 
I. View processes
 
1. ps -- View static process Statistics
 
A: displays information about all processes on the current terminal, including other users.
U: outputs process information in user-based format
X: displays the process information of the current user on all terminals.
-E: displays information about all processes in the system.
-L: Display process information in long format
-F: displays process information in the complete format.
Usage habits: ps aux or ps-elf
 
2. top -- view the dynamic information of a process
Sort by P by cpu, sort by M memory, sort by N startup time, and exit by q
 
3. pgrep -- query process information
Used to query a specified process
For example, query the process ID that contains "log" in the process name and list the process names.
[Root @ localhost ~ ] # Pgrep-l "log"
For example, query the PID number of the process run by the user teacher (with-U) on the tty1 terminal (-t), and list the corresponding process name
[Root @ localhost ~ ] # Pgrep-l-U teacher-t tty1
 
4. pstree -- view the process tree
Display in tree structure, display PID number in combination with-p, list username in-u, and list complete commands in-
[Root @ localhost ~ ] # Pstree [-aup]
For example, list the tree structure information of processes opened by user teacher and sub-processes.
[Root @ localhost ~ ] # Pstree-ap teacher
 
II. Process control
 
1. start the process (manual start and scheduled scheduling start)
 
Manual start includes foreground start and background start, most commands are run on the foreground, you can use Ctrl + Z to suspend the foreground process to the background, but it is paused after being transferred to the background!
 
[Root @ localhost ~ ] # Jobs-l (background process tasks in the current terminal)
[Root @ localhost ~ ] # Fg 1 (re-call the process with PID 1 to the foreground)
 
2. terminate the process (kill, killall, and pkill)
 
(1) kill -- the PID of the process must be set as the parameter! You can use the-9 option to forcibly kill a process!
(2) killall -- use the specified process name as a parameter, or use-9 to force the process to end.
(3) pkill: you can specify a user and a terminal based on the process name, the user who runs the process, and the terminal where the process is located (-U specifies the user and-t specifies the terminal)
 
Final
 
This article is from the "Tiandao reward Qin-Chang Shuangyang" blog
Related Article

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.