OPS Note 6 (Process, user login audit, system service)

Source: Internet
Author: User
Tags memory usage semaphore ssh cpu usage pkill

Overview:

Process understanding and Viewing (PS command), process priority (NICE), process pre-and post-switchover (BG,FG), Process signal (kill), User login audit (last,w, etc.), dynamic view of process status (Top command), The various services of the system (using Systemctl in Enterprise 7), the first service openssh-server.

1. Understanding and viewing of the process

We generally use the PS command to monitor and control the process, to see the status, memory, CPU usage.

PS Parameters

A # #关于当前环境的所有进程 that shows all user processes (self and other users including root)

X # #与当前环境无关的所有进程, shows the process without control terminal.

F # #显示进程的从属关系

E # #显示当前用户环境的所有进程, basically the same as a

L # #长格式输出

U # #显示用户信息

-O # #可以指定显示进程的某些信息,%CPU shows the process CPU load,%mem shows the process memory load, user process users, PID process PID numbers, group process groups, Comm process name (or process binaries), nice process priority, Where you can add--sort to these options, plus the options above, the options can be preceded by +|-to represent the positive or reverse order.

PS Ax-o%cpu,comm--sort <+|-%cpu>

We actually generally use the PS command very little, just remember PS aux is showing all processes, if you need to see the process of the Affiliation plus F can not add-oh. The general display information with the L parameter will be more comprehensive. Let's explain some of his implications.


F represents the process flag, 4 indicates that the process's permissions are root (which can be understood as the process's executor as root, regardless of the binary file plus the adventure bit), and 1 indicates that the process can replicate, but cannot perform exec.

The PRI represents the priority of the process, and sometimes ni,vsz represents the amount of virtual memory used by the process, RSS, which represents the fixed amount of memory occupied by the process. Stat represents the state of the process, generally, R (Running): The process is running, S (sleep) The process is currently sleeping but can be awakened, D is not to be awakened, this program is usually waiting for IO. T indicates that it may be stopped in the background, or in a debug state. Z represents the zombie process.

For BSD formats, you may also see:
< high-priority
N Low-priority
L paging is locked in memory (for real-time and custom IO)
s contains child processes
L Multithreading (using Clone_thread, similar to NPTL thread)
+ process groups in the background

2. Priority of the process

1). Priority view

PS A-o Pid,user,nice,comm to see the priority of all processes related to the current environment.

The priority is range, 20 to 19, and the smaller the number, the faster the CPU is executed by the CPU.

Use the nice command to have a program run at the priority we set.


The Renice command re-sets the priority of an existing process.

3. Front and rear switch of the process

Jobs # #查看在后台的程序

CTRL + Z # #把占用终端的进程打入后台

FG # #将后台进程恢复到前台

BG # #把后台暂停的进程运行

Comm & # #让进程直接在后台运行

Tips,jobs just looks at the program that is entering the background in the current Shell subprocess. After entering the other shell, you cannot display another shell's background process with jobs.

Jobs-l can display the PID of the process

4. Process Signal

1 # #进程重新加载配置

2 # #删除进程在内存中的数据

3 # #删除鼠标在进程中的数据

9 # #强制结束单个进程

# #正常关闭进程

# #运行暂停的进程

# #暂停某个进程

# #把某个进程打入后台


Using the kill-signal process PID

Killall-Signal Process name # #向与这个进程同名的进程都发出信号

Pkill used to view or send a signal to a process by name or by other means

Pkill-u student-signal sends a signal to all student users ' processes. Pkill-9-T terminal number, you can turn off all processes of a terminal.

Below we apply the semaphore, just send the semaphore through the kill command, to achieve the operation in the foreground of vim into the background, the normal end

Finally, VIM does not end, it is because the normal end of VIM will have other end process, need to re-enter vim before exiting.

5. User Login Audit

W # #查看当前使用系统的用户有哪些

W-f # #查看使用地点 (can be said to be IP)

Last # #查看历史登陆成功命令

LASTB # #查看历史登陆失败记录

6.top command

Can look at the situation of each process in the system, although there are many commands, but we just need to remember some basic, such as press 1 to see the use of other multiple CPUs, ' P ' can sort the process by CPU usage, ' M ' can be sorted by memory usage.

7. System service Control (in Red Hat 7 lower systemcyl, Enterprise 6 is init, can be queried by Pstree command)

SYSTEMCTL System Initialization program, the system starts the first program, PID is 1

1). systemctl command

Systemctl List-units # #列出当前系统服务的状态

Systemctl Lsit-units-files # #查看服务的开机状态

Systemctl Status sshd # #查看指定服务的状态

Systemctl Stop sshd # #关闭指定服务

Systemctl Statr sshd # #开启指定服务

Systemctl Enabel sshd # #指定服务开机启动

Systemctl Disabel sshd # #指定服务开机关闭

Systemctl Reload sshd # #指定服务重新加载配置

Systemctl Enabel sshd # #查看指定服务的依赖关系

Systemctl Mask sshd # #冻结指定服务

Systemctl umask sshd # #启用指定服务

Systemctl Set-default Multi-user.target # #开机不启动图形

Systemctl Set-default Graphical.target # # #开机启动图形

2). Status of the service


Loaded # #系统服务已经初始化完成, loaded configuration

Active (running) # #服务正在被系统利用

Active (exited) # #服务已经加载配置, Waiting for system utilization

Active (Waiting) # #服务等待被系统处理

Inactive # #服务关闭

Enabled # #服务开机启动

Disabled # #服务开机不启动

Static # #服务开机启动启动项不可被管理

Failed # #系统配置错误


Tips: This is the Enterprise 7 configuration, in a future article will introduce the Enterprise 6 system service management commands.

8.openssh-server

1) Ssh-keygen generate public key private key

Id_rsa # #私钥 (equivalent to a key)

Id_rsa.pub # #公钥 (equivalent to lock)

2) ssh-copy-id-i/root/.ssh/id_rsa.pub Root@ip

Ssh-copy-id # #添加key认证方式和的工具

-I # #指定加密文件

/root/.ssh/id_rsa.pub # #加密key

Root # #被加密用户为root

IP # #被加密主机ip

3) The key to the other host, so that the message after the communication with Id_rsa.pub encryption and decryption with the key is good.

4)/etc/ssh/sshd_config is the Openssh-server configuration file


Practice:










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.