linux的进程和作业控制实验报告,Linux基础--进程管理和作业控制

用于进程管理和作业控制的主要命令如下图所示。

0818b9ca8b590ca3270a3433284dd417.png

大部分命令都是对进程运行状态进行查询和监控的,而工作中与进程相关的也基本就是监控进程运行状态,检查影响系统运行瓶颈在哪里,然后进行调忧工作。因此本文只着重介绍常用的进程监控命令的监控信息所代表的含义,至于命令怎么使用可以参照man手册或其他文档。如:[12个进程管理命令介绍]

1.ps - report a snapshot of the current processes.

ps有三个不同风格的用法,GNU的长选项风格就不提了,比较难记。还是说说比较常用的两个经典组合吧。一个是BSD风格的ps aux,一个是unix风格的ps -efF。

0818b9ca8b590ca3270a3433284dd417.png

USER:启动此进程的用户

PID:进程号

%CPU:CPU占用率

%MEM:内存占用率

VSZ:虚拟内存集

RSS:常驻内存集

vsz         VSZ     virtual memory size of the process in KiB (1024-byte units). Device

mappings are currently excluded; this is subject to change.

(alias vsize).

rss         RSS     resident set size, the non-swapped physical memory that a task has

used (in kiloBytes). (alias rssize, rsz).

TTY:启动此进程的终端,'?'表示系统后台启动的进程。

STAT:进程运行状态

PROCESS STATE CODES

Here are the different values that the s, stat and state output specifiers

(header "STAT" or "S") will display to describe the state of a process.

D    Uninterruptible sleep (usually IO)

R    Running or runnable (on run queue)

S    Interruptible sleep (waiting for an event to complete)

T    Stopped, either by a job control signal or because it is being traced.

W    paging (not valid since the 2.6.xx kernel)

X    dead (should never be seen)

Z    Defunct ("zombie") process, terminated but not reaped by its parent.

For BSD formats and when the stat keyword is used, additional characters may be

displayed:

N    low-priority (nice to other users)

L    has pages locked into memory (for real-time and custom IO)

s    is a session leader

l    is multi-threaded (using CLONE_THREAD, like NPTL pthreads do)

+    is in the foreground process group

START:进程启动时间/日期

TIME:在CPU上执行的累计时长

COMMAND:启动此进程的命令,'[]'表示内核启动的线程。

0818b9ca8b590ca3270a3433284dd417.png

PPID:父进程号

C:CPU占用率

SZ:进程实际占用物理内存大小,包含文本、数据和栈空间。

PSR: 进程当前运行在CPU的哪个核心上

C           pcpu      cpu utilization

sz          SZ        size in physical pages of the core image of the process.  This

includes text, data, and stack space.  Device mappings are currently

excluded; this is subject to change.  See vsz and rss.

psr         PSR       processor that process is currently assigned to.

2. top - display Linux processes

0818b9ca8b590ca3270a3433284dd417.png

比较难懂点的就是load average和%CPU那两行了。我觉得man手册写的挺好,直接贴了。

system load avg over the last 1, 5 and 15 minutes

Line 2 shows CPU state percentages based on the interval since the last refresh.

As a default, percentages for these individual categories are displayed.  Where two labels

are shown below, those for more recent kernel versions are shown first.

us, user    : time running un-niced user processes

sy, system  : time running kernel processes

ni, nice    : time running niced user processes

id, idle    : time spent in the kernel idle handler

wa, IO-wait : time waiting for I/O completion

hi : time spent servicing hardware interrupts

si : time spent servicing software interrupts

st : time stolen from this vm by the hypervisor

下面的字段含义:

VIRT:虚拟内存集

RES:常驻内存集

SHR:共享内存集

S: 进程运行状态

20. S  --  Process Status

The status of the task which can be one of:

D = uninterruptible sleep

R = running

S = sleeping

T = stopped by job control signal

t = stopped by debugger during trace

Z = zombie

重点说下PR和NI

PR:进程优先级。1-99:实时优先级,数字越大优先级越高,系统自动安排;100-139:静态优先级,数字越小优先级越高,可手动更改。说明:rt为real time,实时优先级;20实际为100+20,显示为20而已.

NI:Nice Value。-20至19,对应于优先级100到139。因此可以通过renice命令来调整nice值进而改变进程优先级,或者使用nice命令指定进程启动的nice值,不指定时使用默认nice值0。普通用户只能通过调整nice值降低进程优先级,而root则可以随意调整。

3. htop - interactive process viewer

0818b9ca8b590ca3270a3433284dd417.png

htop是由epel源提供的软件包,需要额外安装。界面美观很多,甚至可以使用鼠标交互。字段信息跟top是一致的,不另外介绍了,你值得拥有。

4. dstat - versatile tool for generating system resource statistics

0818b9ca8b590ca3270a3433284dd417.png

可以自定义参数的,默认使用了-cdngy。

-c, --cpu

enable cpu stats (system, user, idle, wait, hardware interrupt, software interrupt

-d, --disk

enable disk stats (read, write)

-n, --net

enable network stats (receive, send)

-g, --page

enable page stats (page in, page out)

-y, --sys

enable system stats (interrupts, context switches)

选项含义和字段含义都解释的很清楚吧,所以最好不过man手册。

5. kill/killall/pkill

kill实际上是给进程发送信号量的,并不一定是杀死进程,也可以是让进程reload或者从挂起状态转为继续运行状态的。

0818b9ca8b590ca3270a3433284dd417.png

以上是所有可用的信号量,而常用的一般是以下几个:

1)SIGHUP:无须关闭进程而让其重读配置文件。

2)SIGINT:终止正在运行的进程,相当于Ctrl+C,中断。

9)SIGKILL:杀死运行中的进程。

15)SIGTERM:终止运行中的进程;通常终止为后台进程。默认信号量

18)SIGCONT:继续,让后台停止状态进程在后台继续运行。

19)SIGSTOP:停止,将进程送后台,停止状态。

使用时,可以给信号量编号,也可以给信号量全称或者是简称,不指定信号量,使用默认信号量。

killall和pkill也是同样的原理。

6. 作业控制

系统作业分为前台作业和后台作业。

前台作业(foregroud):通过终端启动,且启动后会一直占据终端。

后台作业(backgroud):可以通过终端启动,但启动后即转入后台运行(释放终端)。

让作业运行于后台

对于运行中作业使用Ctrl+Z组合键,将作业送往后台,转为停止状态。相当于发送了SIGSTOP信号量。

对于尚未启动的作业使用在命令后加上'&'来启动,像这样。

[root@localhost ~]# COMMAND &

但这样启动的作业仍然与终端相关,如果希望将其与终端剥离,可以这样。

[root@localhost ~]# nohup COMMAND &

使用jobs命令可以有哪些作业在后台运行或者被挂起。

[root@localhost ~]# jobs

[1]-  Stopped                 top

[2]   Running                 nohup dstat &

[3]+  Stopped                 ping 172.18.0.1

控制后台作业

[root@localhost ~]# fg  [[%]JOB_NUM]:把指定的作业调回前台;

[root@localhost ~]# bg  [[%]JOB_NUM]:让送往后台的作业在后台继续运行;

[root@localhost ~]# kill %JOB_NUM:终止指定的作业;

fg和bg的%可以省,kill的%是不能省的,省了就成了发送信号量了。fg和bg省略JOB_NUM时,默认是指带+号的那个作业。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值