进程命令管理

进程:二进制加载到内存中,CPU执行期中指令整个过程
进程一定是运行中的程序
图片.png
PID 进程ID号

查看进程

ps :简略查看进程
top:动态查看进程
pstree:树状查看进程

图片.png

[root@localhost 2020-3-13]# ps
  PID TTY          TIME CMD
18481 pts/0    00:00:00 bash
18501 pts/0    00:00:00 ps


[root@localhost 2020-3-13]# top
top - 17:55:23 up 108 days, 20:23,  1 user,  load average: 0.00,
Tasks:  64 total,   1 running,  63 sleeping,   0 stopped,   0 zo
%Cpu(s):  0.7 us,  0.3 sy,  0.0 ni, 99.0 id,  0.0 wa,  0.0 hi,  
KiB Mem :  1883496 total,   685784 free,    78456 used,  1119256
KiB Swap:        0 total,        0 free,        0 used.  1617020

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM 
29804 root      10 -10  125024  12516   9608 S  1.0  0.7 
  777 root      20   0  562388  16564   5876 S  0.3  0.9 
29730 root      10 -10   32612   4344   2780 S  0.3  0.2 
    1 root      20   0   51460   3680   2516 S  0.0  0.2 
    2 root      20   0       0      0      0 S  0.0  0.0 
    3 root      20   0       0      0      0 S  0.0  0.0 
    5 root       0 -20       0      0      0 S  0.0  0.0 
    7 root      rt   0       0      0      0 S  0.0  0.0 
    8 root      20   0       0      0      0 S  0.0  0.0 
    9 root      20   0       0      0      0 S  0.0  0.0 
   10 root      rt   0       0      0      0 S  0.0  0.0 
   12 root      20   0       0      0      0 S  0.0  0.0 
   13 root       0 -20       0      0      0 S  0.0  0.0 
   14 root      20   0       0      0      0 S  0.0  0.0 
   
   
[root@localhost 2020-3-13]# pstree
systemd─┬─AliYunDun───23*[{AliYunDun}]
        ├─AliYunDunUpdate───3*[{AliYunDunUpdate}]
        ├─2*[agetty]
        ├─aliyun-service───2*[{aliyun-service}]
        ├─atd
        ├─auditd───{auditd}
        ├─crond
        ├─dbus-daemon
        ├─dhclient
        ├─ntpd
        ├─polkitd───5*[{polkitd}]
        ├─rsyslogd───2*[{rsyslogd}]
        ├─sshd───sshd───bash───pstree
        ├─systemd-journal
        ├─systemd-logind
        ├─systemd-udevd
        └─tuned───4*[{tuned}]

杀死进程

图片.png

kill举例

Terminated :结束,终点

[root@localhost 2020-3-13]# sleep 1000 &
[1] 18529
[root@localhost 2020-3-13]# ps
  PID TTY          TIME CMD
18481 pts/0    00:00:00 bash
18529 pts/0    00:00:00 sleep
18530 pts/0    00:00:00 ps
[root@localhost 2020-3-13]# kill 18529
[root@localhost 2020-3-13]# ps
  PID TTY          TIME CMD
18481 pts/0    00:00:00 bash
18531 pts/0    00:00:00 ps
[1]+  Terminated              sleep 1000

pkill举例

[root@localhost 2020-3-13]# ps
  PID TTY          TIME CMD
18481 pts/0    00:00:00 bash
18537 pts/0    00:00:00 ps
[root@localhost 2020-3-13]# sleep 1000 &
[1] 18538
[root@localhost 2020-3-13]# sleep 1000 &
[2] 18539
[root@localhost 2020-3-13]# sleep 1000 &
[3] 18540
[root@localhost 2020-3-13]# sleep 1000 &
[4] 18541
[root@localhost 2020-3-13]# sleep 1000 &
[5] 18542
[root@localhost 2020-3-13]# ps
  PID TTY          TIME CMD
18481 pts/0    00:00:00 bash
18538 pts/0    00:00:00 sleep
18539 pts/0    00:00:00 sleep
18540 pts/0    00:00:00 sleep
18541 pts/0    00:00:00 sleep
18542 pts/0    00:00:00 sleep
18543 pts/0    00:00:00 ps
[root@localhost 2020-3-13]# pkill sleep
[1]   Terminated              sleep 1000
[2]   Terminated              sleep 1000
[3]   Terminated              sleep 1000
[4]-  Terminated              sleep 1000
[5]+  Terminated              sleep 1000
[root@localhost 2020-3-13]# ps
  PID TTY          TIME CMD
18481 pts/0    00:00:00 bash
18547 pts/0    00:00:00 ps

更改进程(前台执行/后台执行)

末尾加上& ,表示挂在后台执行
jobs显示后台任务
图片.png

[root@localhost 2020-3-13]# sleep 100
^C
[root@localhost 2020-3-13]# ps
  PID TTY          TIME CMD
18481 pts/0    00:00:00 bash
18507 pts/0    00:00:00 ps
[root@localhost 2020-3-13]# sleep 100 &
[1] 18513
[root@localhost 2020-3-13]# ps
  PID TTY          TIME CMD
18481 pts/0    00:00:00 bash
18513 pts/0    00:00:00 sleep
18514 pts/0    00:00:00 ps

转到前台举例

[root@localhost 2020-3-13]# jobs
[root@localhost 2020-3-13]# sleep 1000 &
[1] 18549
[root@localhost 2020-3-13]# jobs
[1]+  Running                 sleep 1000 &
[root@localhost 2020-3-13]# sleep 1000 &
[2] 18550
[root@localhost 2020-3-13]# jobs
[1]-  Running                 sleep 1000 &
[2]+  Running                 sleep 1000 &
[root@localhost 2020-3-13]# fg 1
sleep 1000
^C
[root@localhost 2020-3-13]# jobs
[2]+  Running                 sleep 1000 &

用户管理

图片.png
图片.png

添加/删除用户

主组:默认下,每个用户默认创建的基本组
附加组:除了基本组外,用户可以属于的其他组
一个用户可以有很多组,但是主组只有一个.其余都是附加组

图片.png

/etc/passwd 文件

-g 指定用户的主组

stu 用户id:1001,组id:1001
stu3:用户id:1003,组id:1001
stu和stu3的主组是同一组 stu

[root@localhost home]# useradd -g stu stu3
[root@localhost home]# cat /etc/passwd | grep stu
stu:x:1001:1001::/home/stu:/bin/bash
stu2:x:1002:1002::/home/stu2:/bin/bash
stu3:x:1003:1001::/home/stu3:/bin/bash

/etc/group 文件

-G 指定用户所属附加组

stu除了主组外,TA的附加组 是stu2

[root@localhost home]# useradd -G stu stu2
[root@localhost home]# cat /etc/group | grep stu
Akuaner:x:1000:stu
stu:x:1001:stu2
stu2:x:1002:

/etc/shadow 文件

passwd 设置密码

新建用户无密码

[root@localh home]# cat /etc/shadow | grep stu3
stu3:!!:18336:0:99999:7:::
[root@localh home]# passwd stu3
Changing password for user stu3.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@localh home]# cat /etc/shadow | grep stu3
stu3:$6$shDnKXpO$x.pN6HZDwGp0MmKXEMbYPpdkGkb/lAITw.fnzxNmVb0ZoSifWFnKS.PQP1KW5lE9b8eFhrWyQGzHk0nySlAN2/:18336:0:99999:7:::

Akuaner
7 声望3 粉丝