1. 程式人生 > >[CentOS 7系列]作業控制

[CentOS 7系列]作業控制

作業

1、jobs

[[email protected] ~]# top
top - 06:39:07 up  8:24,  3 users,  load average: 0.01, 0.04, 0.05
Tasks:  87 total,   1 running,  84 sleeping,   2 stopped,   0 zombie
%Cpu(s):  0.5 us,  0.4 sy,  0.0 ni, 99.0 id,  0.1 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  1008392 total,   157936 free,   132356 used,   718100 buff/cache
KiB Swap:  2097148 total,  2097148 free,        0 used.   660208 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
30125 root      20   0  157572   2076   1504 R  6.2  0.2   0:00.01 top
    1 root      20   0   45528   5812   3672 S  0.0  0.6   0:02.34 systemd
    2 root      20   0       0      0      0 S  0.0  0.0   0:00.01 kthreadd
    3 root      20   0       0      0      0 S  0.0  0.0   0:04.36 ksoftirqd/0
    4 root      20   0       0      0      0 D  0.0  0.0   0:38.92 kworker/0:0
    7 root      rt   0       0      0      0 S  0.0  0.0   0:00.00 migration/0
    8 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcu_bh
    9 root      20   0       0      0      0 S  0.0  0.0   0:01.27 rcu_sched
   10 root      rt   0       0      0      0 S  0.0  0.0   0:02.68 watchdog/0
   12 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 khelper
   13 root      20   0       0      0      0 S  0.0  0.0   0:00.00 kdevtmpfs
   14 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 netns
   15 root      20   0       0      0      0 S  0.0  0.0   0:00.01 khungtaskd
   16 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 writeback
   17 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kintegrityd
   18 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 bioset
   19 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kblockd
[1]+  已停止               top                ## ctrl+z 暫停一個任務
[[email protected]
/* */ ~]# cat /etc/passwd | wc -l & ##管道符表示後面的命令作用於前面命令的結果 [2] 30138 ##“&”表示放在後臺運行 [[email protected] ~]# 21 jobs ## jobs命令用於查看後臺的任務 [1]+ 已停止 top [2]- 完成 cat /etc/passwd | wc -l


2、fg

[[email protected] ~]# jobs
[1]-  已停止               top
[2]+  已停止               man fdisk
[[email protected] ~]# fg 1                       ##將任務調度到前臺運行
top - 06:58:25 up  8:43,  3 users,  load average: 0.00, 0.01, 0.05
Tasks: 102 total,   3 running,  82 sleeping,  17 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.2 sy,  0.0 ni, 99.8 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  1008392 total,   153464 free,   136164 used,   718764 buff/cache
KiB Swap:  2097148 total,  2097148 free,        0 used.   656136 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
    4 root      20   0       0      0      0 R  0.2  0.0   0:40.85 kworker/0:0
30083 root      20   0  143020   5556   4252 S  0.1  0.6   0:00.93 sshd
    9 root      20   0       0      0      0 S  0.0  0.0   0:01.34 rcu_sched
  287 root      20   0       0      0      0 S  0.0  0.0   0:08.18 xfsaild/sda3
  502 root      20   0  327432  26912   6556 S  0.0  2.7   0:04.39 firewalld
30087 root      20   0  115508   2168   1764 R  0.0  0.2   0:00.21 bash
    1 root      20   0   45528   5812   3672 S  0.0  0.6   0:02.35 systemd
   10 root      rt   0       0      0      0 S  0.0  0.0   0:02.71 watchdog/0
  801 root      20   0  553152  18520   5816 S  0.0  1.8   0:07.17 tuned
20876 root      20   0       0      0      0 S  0.0  0.0   0:00.41 kworker/u12+
    2 root      20   0       0      0      0 S  0.0  0.0   0:00.01 kthreadd
    3 root      20   0       0      0      0 S  0.0  0.0   0:04.39 ksoftirqd/0
    7 root      rt   0       0      0      0 S  0.0  0.0   0:00.00 migration/0
    8 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcu_bh
   12 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 khelper
   13 root      20   0       0      0      0 S  0.0  0.0   0:00.00 kdevtmpfs
   14 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 netns
   ## ctrl+c  結束一個任務
[[email protected]
/* */ ~]# jobs [2]+ 已停止 man fdisk


3、bg

[[email protected] ~]# jobs
[2]-  已停止               man fdisk
[3]+  已停止               ping -c 100 114.114.114.114
[[email protected] ~]# bg 3                       ##放在後臺繼續運行
[3]+ ping -c 100 114.114.114.114 &
[[email protected] ~]# 64 bytes from 114.114.114.114: icmp_seq=84 ttl=58 time=7.58 ms
64 bytes from 114.114.114.114: icmp_seq=85 ttl=58 time=10.2 ms
64 bytes from 114.114.114.114: icmp_seq=86 ttl=58 time=5.25 ms
job64 bytes from 114.114.114.114: icmp_seq=87 ttl=58 time=11.5 ms
s
[2]+  已停止               man fdisk
[3]-  運行中               ping -c 100 114.114.114.114 &

如果正在運行一個進程,而且希望在退出帳戶時該進程還不會結束,那麽可以使用nohup命令(nohup command &)。該命令可以在用戶退出帳戶之後繼續運行相應的進程。


本文出自 “亂碼時代” 博客,請務必保留此出處http://juispan.blog.51cto.com/943137/1943301

[CentOS 7系列]作業控制