Process management commands
The difference between a process and a program
1. A program is a static concept, which is preserved as a software resource for a long time; while a process is the execution process of a program, which is a dynamic concept, has a certain life span, and is dynamically generated and extinguished.
2 There is no one-to-one correspondence between programs and processes. A process can execute several programs sequentially in an activity.
Parent process and child process
1 A child process is a process generated by a process, and the process that generates this child process is called the parent process.
2 In the Linux system, use the system call fork to create a process. The content copied by fork includes the data and stack segments of the parent process and the process environment of the parent process.
3 The parent process terminates and the child process terminates naturally.
The difference between process and thread
Process: It is the program or command being executed. Each process is a running entity, has its own address space, and occupies certain system resources.
Thread: A lightweight process; a process has an independent address space, but a thread does not; a thread cannot exist independently, it is created by a process; relatively speaking, a thread consumes less CPU and memory than a process.
The role of process management: to judge the health status of the server; to view all the processes in the system; to kill the process.
Foreground process and background process
Foreground process:
After entering the command at the Shell prompt, create a subprocess, run the command, and the Shell waits for the command to exit, and then returns to give the user a prompt. This command runs asynchronously with the Shell, that is, it runs in the foreground, and the user cannot execute another command until it completes.
backstage process:
Enter the command at the prompt of the Shell, if followed by a & amp;, the subprocess created by the Shell runs the command, but does not wait for the command to exit, but directly returns to the
The user gives a prompt. This command runs synchronously with the Shell, that is, it runs in the background. Background processes must be non-interactive.
ps
Function: view process information in the system Syntax: ps [-auxle] Common options a: show processes of all users u: display user name and startup time x: show processes without a controlling terminal e: Show all processes, including those without a controlling terminal l: long format display
View all processes in the system
ps aux #View all processes in the system, using BSD operating system format, unix ps -le #View all processes in the system, using Linux standard command format eg: [root@qianfeng01 ~]# ps -u or ps -l View the detailed information of the processes belonging to you eg: [root@qianfeng01 ~]# ps aux | grep sam View the processes executed by user sam eg: [root@qianfeng01 ~]# ps -ef | grep init View the specified process information
pstree
Function: view the current process tree Syntax: pstree [options] -p display process PID -u Display the owning user of the process
top
Function: View system health status Display the processes that consume the most resources in the current system, as well as some load conditions of the system. Syntax: top [options] -d Seconds, specify a few seconds to refresh once, the default is 3 seconds (dynamic display)
kill
Function: close the process Syntax: kill [-options] pId eg: [root@qianfeng01 ~]# kill -9 process number (forcibly closed) commonly used \t eg: [root@qianfeng01 ~]# kill -1 process number (restart process) eg: [root@qianfeng01 ~]# killall -l close all processes (ignore the case of the process name)
w
Function: view user information Syntax: w username eg: [root@qianfeng01 ~]# w root show: USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root pts/0 10.0.158.3 06:02 0.00s 0.13s 0.00s w root explain: JCPU: It is distinguished by the terminal code name. When all related processes of this terminal are executed, the CPU time consumed will be displayed here PCPU: The time spent by the CPU executing the program WHAT: what the user is doing
nohup
Function: Make the process continue to execute after the user logs out, the nohup command will store the executed data information and error information in the file nohup.out by default Grammar: nohup program & amp; & amp; means to run in the background eg: [root@qianfeng01 ~]# nohup ping www.baidu.com & amp; Use: [root@qianfeng01 ~]# ps -ef | grep ping View the current ping process
uptime
role: view load For example: use uptime to determine whether the server or the network has a problem. If the web application is running, run uptime to see if the system load is high. If the load is not high, the problem is most likely due to the network rather than the server. Syntax: uptime eg: execute: [root@qianfeng01 ~]# uptime Display: 06:32:04 up 19:57, 4 users, load average: 0.00, 0.01, 0.00 Explanation: system time, number of users, average system load of the server in the past 1 minute, 5 minutes, and 15 minutes
User management commands
su
Syntax: su username Role: switch user eg: [root@qianfeng01 ~]# su root Switch back to the root user. Note: If you are the root user, you will be asked to enter a password every time. Ordinary users can switch directly
useradd
Add user Syntax: useradd [options] username
passwd
Change password command Syntax: passwd [options] [username] User password: In the production environment, the length of the user password is more than 8 characters, and the password should be changed regularly. ys^h_L9t
userdel
delete user -r Delete the host directory when deleting the account (remove) Note: A user is already open and needs to be deleted Method: first jump to the current user, execute exit or exit user name. At this time, it will automatically jump back to the root interface. If it still cannot be deleted, you can restart the system
groupadd
for adding groups -g specifies the gid
groupmod
is used to modify the group -n change group name (new group) [root@qianfeng01 ~]# groupmod -n new_gname old_gname
groupdel
is used to delete a group If the group to be deleted belongs to the group to which a certain user belongs, the group cannot be deleted [root@qianfeng01 ~]# useradd -g hadoop hdfs [root@qianfeng01 ~]# groupdel hadoop
File permission command
Three basic permissions
r read permission (read) w Write permission (write) x execute permission (execute)
Permission Description
Owner Group Others
Bit 1: file type (d directory, – normal file, l link file)
No. 2-4: the user (owner) authority, represented by u (user)
Bits 5-7: the authority of the group to which it belongs, represented by g (group)
No. 8-10: Other users (other people) permissions, expressed by o (other)
No. 2-10: Indicates all permissions, represented by a (all)
eg: -rw-r–r–. 1 root root 3664 Nov 30 17:42 CentOS-Vault.repo.bak
The 11th digit represents the number of hard links
characters | permissions | meaning for files | meaning for directories |
---|---|---|---|
r | Read permission | You can view the contents of the file | You can list the contents of the directory (ls ) |
w | Write permissions | Can modify file content | Can create and delete files in the directory ( mkdir,rm ) |
x | execution permission | can execute files | can enter the directory ( cd) |
For files we have commands with execute permission:
r-cat, more, head, tail, less
w-echo,vi
x – command, script
For directories, we have commands with execute permissions:
r-ls
w-touch, mkdir, rm, rmdir
x-cd
The permission to delete a file must have wx permission on the directory where the file is located.
chmod
for permission changes English: change mode (change the permissions mode of a file) Role: Change file or directory permissions grammar: chmod [{ugoa}{ + -=}{rwx}][filename or directory] chmod [mode=421][file or directory] Parameters: -R The files and subdirectories below do the same permission operation (Recursive recursive) Can have permission to modify a file: 1. root 2. File Owner eg: [root@qianfeng01 ~]# chmod u + x a.txt eg: [root@qianfeng01 ~]# chmod u + x,o-x a.txt Use numbers to represent permissions (r=4, w=2, x=1, -=0) eg: [root@qianfeng01 ~]# chmod 750 b.txt rwx and digital representation can be switched at will Note: The root user is a super user, and root can make changes regardless of permissions. Test permissions with normal user. It is not possible to use an ordinary user to modify the permissions of another ordinary user.
chown
for changing owner English: change file ownership Role: Change the owner of a file or directory Syntax: chown user[:group] file... -R : recursive modification Parameter format: user : the user ID of the new file owner group : the user group of the new file owner eg: [root@qianfeng01 ~]# chown lee file1 Change the owner of file1 to user lee eg: [root@qianfeng01 ~]# chown lee:test file1 Change the owner of file1 to user lee, and the group to test eg: [root@qianfeng01 ~]# chown –R lee:test dir Modify the owner and group of dir and its subdirectories
chgrp
is used to change the belonging group English: change file group ownership Function: Change the group to which a file or directory belongs Syntax: chgrp [group] file... eg: [root@qianfeng01 ~]# chgrp root test.log Change the group of test.log to root
Configuration of sudo permissions
Function
Root assigns commands that can only be executed by super users to ordinary users.
The operation object of sudo is the system command
Modify the sudoers file
Execute [root@qianfeng01 ~]# visudo The actual modification here is the /etc/sudoers file Interpretation of information inside the sudoers file root ALL=(ALL) ALL #User name The address of the managed host (not the access address) = (usable identity) Authorization command (absolute path) %wheel ALL=(ALL) ALL #%group name The address of the managed host = (identity that can be used) Authorization command (absolute path) [root@qianfeng01 ~]# sudo -l View available sudo commands Notice: The sudo command is used to execute commands with other identities, and the default identity is root. Users who can execute sudo commands are set in /etc/sudoers. If an unauthorized user attempts to use sudo, a warning email will be sent to the administrator. When using sudo, the user must first enter the password, and then there is a 5-minute validity period, after which the password must be re-entered.
Grammar
sudo (options) (arguments) options -b: Execute commands in the background; -h: display help; -H: Set the HOME environment variable to the HOME environment variable of the new identity; -k: End the validity period of the password, that is, you need to enter the password when you execute sudo next time; -l: List the commands that the current user can execute and cannot execute; -p: change the prompt symbol for asking password; -s: Execute the specified shell; -u<user>: Use the specified user as the new identity. If this parameter is not added, root will be used as the new identity by default; -v: Extend the validity period of the password by 5 minutes; -V : Display version information.