Red Hat study notes [RHCSA] Lesson

Lesson Six

process

Process : run an executable program has been launched in the instance. Each process has its own address space, and take up a certain amount of system resources.

How to generate a process

  1. Execute a program or command
  2. Scheduled Tasks

In the terminal for process management

  1. Run a foreground process
[root@master Desktop]# firefox

(process:3731): GLib-CRITICAL **: g_slice_set_config: assertion `sys_page_size == 0' failed
# 会占用当前得终端
  1. Run a background process
[root@master Desktop]# firefox &
[1] 3796
[root@master Desktop]# 
(process:3796): GLib-CRITICAL **: g_slice_set_config: assertion `sys_page_size == 0' failed

[root@master Desktop]# 
  1. jobs have to see the process under the current terminal
[root@master Desktop]# jobs
[1]+  Running            
  1. Foreground background switch
# 切换到前端 终端又被占用
root@master Desktop]# fg 1
firefox
# 切换到后端
root@master Desktop]# bg 1

Systemd control service starts, the daemon

  1. Status of the service unit
loaded   服务单元的配置文件已被处理
active (running)    运行中
active(exited)  某些一次性运行的服务已经陈工被执行并退出
active(waiting)服务已经运行,但正在等待某个时间
inactive    没运行
disabled 开机不运行
enabled 开机运行
static  不能够被设置为开机启动 
  1. systemd command
# 查看服务状态
systemctl status sshd
# 开启
systemctl start sshd
# 结束
systemctl stop sshd
# 重启
systemctl restart sshd
# 是否开机启动
systemctl is-enabled sshd
# 是否活动
systemctl is-active sshd
# 列出所有的服务单元
systemctl list units 
# 列出所有服务单元文件
systemctl  list-unit-files 

The course covers the command

ps -auxView the process

Note: This command without -also easy to use.

# a显示所有前台进程,x显示所有后台进程 u显示用户
[root@centos ~]# ps -aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0  51896  3256 ?        Ss   Jul02   1:59 /usr/lib/systemd/systemd --system --deserialize 21
root         2  0.0  0.0      0     0 ?        S    Jul02   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    Jul02   1:54 [ksoftirqd/0]
root         5  0.0  0.0      0     0 ?        S<   Jul02   0:00 [kworker/0:0H]
root         7  0.0  0.0      0     0 ?        S    Jul02   0:23 [migration/0]
root         8  0.0  0.0      0     0 ?        S    Jul02   0:00 [rcu_bh]
root         9  0.0  0.0      0     0 ?        S    Jul02   6:56 [rcu_sched]
root        10  0.0  0.0      0     0 ?        S    Jul02   1:31 [watchdog/0]
  • Top row information presentation
USER    哪个用户产生进程
PID     进程号
%CPU    占用cpu资源的百分比
%MEM    占用物理内存的百分比
VSZ     虚拟内存的占用
RSS     占用物理内存的大小单位(kb)
TTY     只以哪一个控制台(终端)运行程序
STAT    状态
        R 表示正在运行
        +表示后台进程
        S表示睡眠状态的进程
        s包含子进程(父进程停止,子进程也会停止)
        T停止状态的进程(显示T的可以被唤醒)
START   进程的启动时间
TIME    进程占了CPU多长时间
COMMAND 这个进程哪个命令来的

ps -leView the process

# l显示详细信息 e显示左右进程 f标准格式
[root@centos ~]# ps -efl
F S UID        PID  PPID  C PRI  NI ADDR SZ WCHAN  STIME TTY          TIME CMD
4 S root         1     0  0  80   0 - 12974 ep_pol Jul02 ?        00:01:59 /usr/lib/systemd/systemd --system --deserialize 21
1 S root         2     0  0  80   0 -     0 kthrea Jul02 ?        00:00:00 [kthreadd]
1 S root         3     2  0  80   0 -     0 smpboo Jul02 ?        00:01:54 [ksoftirqd/0]
1 S root         5     2  0  60 -20 -     0 worker Jul02 ?        00:00:00 [kworker/0:0H]
1 S root         7     2  0 -40   - -     0 smpboo Jul02 ?        00:00:23 [migration/0]

top View dynamic process

top - 17:05:45 up 56 days,  6:46,  1 user,  load average: 0.11, 0.05, 0.05
Tasks: 126 total,   1 running, 125 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.3 us,  0.2 sy,  0.0 ni, 99.5 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  5946700 total,   783956 free,  3881272 used,  1281472 buff/cache
KiB Swap:  4194300 total,  4097288 free,    97012 used.  1686820 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                                                                                         
15056 root      20   0  990364  31204   7096 S   0.7  0.5  34:30.57 dockerd-current                                                                                                                                                 
12612 root      20   0       0      0      0 S   0.3  0.0   0:00.06 kworker/1:1   
  • top has an interactive command
    ? 或H 弹出帮助信息
​   P 以CPU的使用率排序
​   M 以内存的使用率排
​   N 以PID的顺序排
​   q退出top
  • Meaning top the top of the display
# 第一行
当前时间 开机时间 几个用户 资源使用率:1分钟,5分钟,15分钟
# 第二行
总共任务数  运行的  睡眠的  停止的  僵尸进程
`注:什么是僵尸进程:父进程停止了 子进程没停止叫做僵尸进程。`
# 第三行
CPU使用率  us用户占用sy 系统占用的 ni改变过优先级的进程占用的 id空闲的  wa 等待进程  hi 硬件中断占用的  si 软中断占用的  st 有虚拟机是,虚拟占用的
# 第四行
物理内存:总数 使用中 空闲的  缓存区
# 第五行
虚拟内存:总数 使用中 空闲的  缓存区
# 第六行
PID USER PR 优先级 NI nice值   VIRT 申请的虚拟内存 RES常驻内存实际的 SHR 共享的  S 状态

freeView memory usage

# -h 是以人类能看的懂得样式输出
[root@centos ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           5.7G        3.7G        760M         33M        1.2G        1.6G
Swap:          4.0G         94M        3.9G

pstree Tree display process

# -p参数是显示子进程
[root@centos ~]# pstree -p
systemd(1)─┬─NetworkManager(701)─┬─{NetworkManager}(726)
           │                     └─{NetworkManager}(729)
           ├─abrt-watch-log(7869)
           ├─abrtd(7850)
           ├─atd(7480)
           ├─auditd(24144)───{auditd}(24153)
           ├─crond(31725)
           ├─dbus-daemon(660)

kill Kill the process

# -l  查看信号 -1 重启(让进程立即关闭,然后重新读取配置文件)-2 强制结束 (终止,力度轻)-9 强制结束 (强制关闭,用来立即结束程序)
# -15 正常终止 (正常关闭)-18 恢复后台 (可以让暂停的进程恢复执行,本信号不能被阻断)-19 前台与运行的放在后台(该信号可以暂停前台进程,相当于CTRL+Z。本新号不能被阻断)
[root@centos ~]# kill -15 pid

killall pkillKill process with a process name

Guess you like

Origin www.cnblogs.com/primadonna/p/11422402.html