day3-计划任务+进程

系统服务

服务

独立监听的、响应速度快、持续战胜系统资源

临时服务

响应较慢、有访问时启用、更节省资源

路径

系统服务(脚本):/etc/rc.d/init.d/*

临时服务(配置文件):/etc/xinetd.d/*

列出所有系统服务

ll /etc/init.d/

列出所有临时服务

ls /etc/xinetd.d/

系统服务控制

Service 服务名称 控制参数

/etc/init.d/本条例名称 控制参数

start         :启动

stop:停止

status:查看服务当前状态

restart:重新启动

reload:重新加载配置文件

xinetd 超级服务器

eXtended InterNET service daemon

超级守护进程、超级服务器

统一管理多个TCP/UDP服务、控制访问权限

[root@localhost ~]# vim /etc/xinetd.d/rsync

# default: off

# description: The rsync server is a goodaddition to an ftp server, as it

#      allows crc checksumming etc.

service rsync                      服务器

{

        disable = yes                                        是否禁用

       flags           = IPv6

        socket_type     = stream          套接字类型

        wait            = no         Yes单线程,no多线程

        user            = root         服务的运行身份

       server          = /usr/bin/rsync     可执行程序路径

       server_args     = --daemon                   执行选项/参数

       log_on_failure  += USERID              失败时日志补充

}

~     

临时服务控制

chkconfig –list 服务名

chkconfig [--level  级别列表] 服务名 on|off

chkconfig –-list         查看服务开关状态

service xinetd reload

ntsysv可视化工具

ntsysv –level 运行级别列表

计划任务

一次性计划任务

at命令

系统服务:/etc/init.d/atd

任务存放位置:/var/spool/at

[root@localhost ~]# date

2016年 08月 10日 星期三 22:04:10 CST

[root@localhost ~]# at 22:06 2016-08-10

at> /bin/echo aaaa >>/mnt/a.txt

at> <EOT>    按ctrl+d键提交计划

        按ctrl+c键中止当前操作  

job 7 at 2016-08-10 22:06

[root@localhost ~]# atq

72016-08-10 22:06 a root

[root@localhost ~]# cat /mnt/a.txt 

aaaa

[root@localhost ~]# date

2016年 08月 10日 星期三 22:08:37 CST

[root@localhost ~]# at 23:00

at> /bin/echo bbbb >>/mnt/a.txt                                          

at> <EOT>

job 8 at 2016-08-10 23:00

[root@localhost ~]# at 23:01

at> /bin/echo cccc >>/mnt/a.txt    

at> <EOT>

job 9 at 2016-08-10 23:01

[root@localhost ~]# atq

82016-08-10 23:00 a root

92016-08-10 23:01 a root

删除指定的计划

[root@localhost ~]# atq

82016-08-10 23:00 a root

92016-08-10 23:01 a root

[root@localhost ~]# atrm 8

[root@localhost ~]# atq

92016-08-10 23:01 a root

周期性计划任务

系统服务:/etc/init.d/crond

用户计划:/var/spool/cron/用户名

默认的计划任务

全局配置:/etc/crontab

系统计划:/etc/cron.hourly/*

    /etc/cron.daily/*

    /etc/cron.weekly/*

    /etc/cron.monthly/*

格式

wKioL1eqxuiyrwRdAADFvMGYfEE653.png-wh_50

  • *:匹配范围内任意时间

  • ,:表示多个不连续的时间点

  • -:表示连续的时间范围

  • /n:指定时间频率,每n ...

0 9 * * 1-5 周一到周五 每天9点

45 10 * * 4,5 每周四/五 10点45分

0 9-21/2 * * * 9点到21点之间第2小时执行一次

0 0 0 */3 * * 每3天的0点

编辑cron计划任务

格式:crontab -e [-u 用户名]

查看cron计划任务

crontab -l [-u 用户名]

删除cron计划任务

crontab -r [-u 用户名]

计划任务的授权

at 任务控制

/etc/at/at.allow、/etc/at.deny

cron 任务控制

/etc/cron.allow、/etc/cron.deny

[root@localhost ~]# ls /etc/{at,cron}*.{allow,deny}

ls: 无法访问/etc/at*.allow: 没有那个文件或目录

ls: 无法访问/etc/cron*.allow: 没有那个文件或目录

/etc/at.deny  /etc/cron.deny

注:

如果allow文件存在,则公允许指定的用户

否则检查deny文件,除指定用户外其余都允许

如果两个文件都不存大,则只允许root使用

anacron延时补救

适合不需要24小时持续运行的主要

 任务周期:每小时检查一次,最近x天以内的任务

 由crond服务调度检查,执行被错过的任务操作

[root@localhost ~]# rpm -qa|grep anacron

cronie-anacron-1.4.4-7.el6.x86_64

[root@localhost ~]# rpm -ql cronie-anacron |grep etc

/etc/anacrontab    全局配置

/etc/cron.hourly/0anacron    检查任务脚本

/etc/anacrontab 格式

周期 延时 任务名称 命令行

[root@localhost ~]# tail -n 3 /etc/anacrontab 

15cron.dailynice run-parts /etc/cron.daily

725cron.weeklynice run-parts /etc/cron.weekly

@monthly 45cron.monthlynice run-parts /etc/cron.monthly

程序和进程

程序

保存在磁盘中的可执行文件

是静态保存的代码

进程

在CPU及内存中运行的程序指令

是动态执行的代码

父/子进程:进程可以创建一个或多个子进程

查看进程树

psree Processes Tree

格式:pstree [选项] [PID或用记名]

-a:显示完整的命令行

-u:列出各进程所属的用户名

-p:列出对就的PID号

[root@localhost ~]# pstree -aup

init,1

  ├─ManagementAgent,1503

  │   ├─{ManagementAgen},1510

  │   └─{ManagementAgen},1511

  ├─VGAuthService,1385 -s

  ├─abrtd,2135

  ├─acpid,1869

  ├─atd,2154

  ├─auditd,1687

  │   └─{auditd},1688

  ├─certmonger,2167 -S -p /var/run/certmonger.pid

  ├─crond,2143

  ├─cupsd,1844 -C /etc/cups/cupsd.conf

  ├─dbus-daemon,1771,dbus --system

  │   └─{dbus-daemon},1772

  ├─hald,1878,haldaemon

  │   └─hald-runner,1879,root

  │       ├─hald-addon-acpi,1928,haldaemon

  │       └─hald-addon-inpu,1920

  ├─master,2111

  │   ├─pickup,2448,postfix -l -t fifo -u

  │   └─qmgr,2118,postfix -l -t fifo -u

  ├─mingetty,2179 /dev/tty1

  ├─mingetty,2181 /dev/tty2

  ├─mingetty,2183 /dev/tty3

  ├─mingetty,2188 /dev/tty4

  ├─mingetty,2190 /dev/tty5

  ├─mingetty,2192 /dev/tty6

  ├─rpc.idmapd,1829

  ├─rpc.statd,1790,rpcuser

  ├─rpcbind,1755,rpc

  ├─rsyslogd,1712 -i /var/run/syslogd.pid -c 5

  │   ├─{rsyslogd},1713

  │   ├─{rsyslogd},1714

  │   └─{rsyslogd},1715

  ├─sshd,1945

  │   └─sshd,2207 

  │       └─bash,2211

  │           └─pstree,2465 -aup

  ├─udevd,442 -d

  │   ├─udevd,2186 -d

  │   └─udevd,2187 -d

  ├─vmtoolsd,1324

  │   └─{vmtoolsd},1398

  └─vmware-vmblock-,1288 -o subtype=vmware-vmblock,default_permissions,allow_other/v

      ├─{vmware-vmblock},1289

      └─{vmware-vmblock},1290

查看进程快照

ps    Processes Snapshot

ps [选项]

-a:显示当前终端下的所有进程

-u:使用以用户为主的格式输出信息

-x:显示当前用户在所有终端下的进程

-e:显示系统内所有的进程

-l:使用长格式输出信息

-f:以最完整的格式输出信息

Ps命令主要记住两个组合:一个是“aux”,记住前面没有“-”,另一个是“-elf”。要记住一点“-elf”,显示结果中有PPID为父ID值。

wKioL1eq122hikbWAAAukykaGsg006.png

PID:既标识了一个进程,也说明了这个进程启动的顺序。

程序:保存在磁盘中的可执行文件,是静态保存的代码。

进程:在CPU及内存中运行的程序指令或是动态执行的代码。

父/子进程:进程可以创建一个或多个子进程。

Linux运行的用第一个进程为init进程号为1。

列出下在运行的所有进程

[root@localhost ~]# ps aux

USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND

root          1  0.0  0.6  19352  1412 ?        Ss   21:34   0:01 /sbin/init

root          2  0.0  0.0      0     0 ?        S    21:34   0:00 [kthreadd]

root          3  0.0  0.0      0     0 ?        S    21:34   0:00 [migration/0]

root          4  0.0  0.0      0     0 ?        S    21:34   0:00 [ksoftirqd/0]

root          5  0.0  0.0      0     0 ?        S    21:34   0:00 [migration/0]

root          6  0.0  0.0      0     0 ?        S    21:34   0:00 [watchdog/0]

root          7  0.0  0.0      0     0 ?        S    21:34   0:00 [migration/1]

root          8  0.0  0.0      0     0 ?        S    21:34   0:00 [migration/1]

root          9  0.0  0.0      0     0 ?        S    21:34   0:00 [ksoftirqd/1]

root         10  0.0  0.0      0     0 ?        S    21:34   0:00 [watchdog/1]

root         11  0.0  0.0      0     0 ?        S    21:34   0:00 [events/0]

root         12  0.0  0.0      0     0 ?        S    21:34   0:04 [events/1]

root         13  0.0  0.0      0     0 ?        S    21:34   0:00 [cgroup]

root         14  0.0  0.0      0     0 ?        S    21:34   0:00 [khelper]

root         15  0.0  0.0      0     0 ?        S    21:34   0:00 [netns]

root         16  0.0  0.0      0     0 ?        S    21:34   0:00 [async/mgr]

root         17  0.0  0.0      0     0 ?        S    21:34   0:00 [pm]

root         18  0.0  0.0      0     0 ?        S    21:34   0:00 [sync_supers]

root         19  0.0  0.0      0     0 ?        S    21:34   0:00 [bdi-default]

root         20  0.0  0.0      0     0 ?        S    21:34   0:00 [kintegrityd/0]

root         21  0.0  0.0      0     0 ?        S    21:34   0:00 [kintegrityd/1]

root         22  0.0  0.0      0     0 ?        S    21:34   0:00 [kblockd/0]

root         23  0.0  0.0      0     0 ?        S    21:34   0:00 [kblockd/1]

root         24  0.0  0.0      0     0 ?        S    21:34   0:00 [kacpid]

root         25  0.0  0.0      0     0 ?        S    21:34   0:00 [kacpi_notify]

root         26  0.0  0.0      0     0 ?        S    21:34   0:00 [kacpi_hotplug]

root         27  0.0  0.0      0     0 ?        S    21:34   0:00 [ata/0]

root         28  0.0  0.0      0     0 ?        S    21:34   0:00 [ata/1]

root         29  0.0  0.0      0     0 ?        S    21:34   0:00 [ata_aux]

root         30  0.0  0.0      0     0 ?        S    21:34   0:00 [ksuspend_usbd]

root         31  0.0  0.0      0     0 ?        S    21:34   0:00 [khubd]

root         32  0.0  0.0      0     0 ?        S    21:34   0:00 [kseriod]

root         33  0.0  0.0      0     0 ?        S    21:34   0:00 [md/0]

root         34  0.0  0.0      0     0 ?        S    21:34   0:00 [md/1]

root         35  0.0  0.0      0     0 ?        S    21:34   0:00 [md_misc/0]

root         36  0.0  0.0      0     0 ?        S    21:34   0:00 [md_misc/1]

root         37  0.0  0.0      0     0 ?        S    21:34   0:00 [khungtaskd]

root         38  0.0  0.0      0     0 ?        S    21:34   0:00 [kswapd0]

root         39  0.0  0.0      0     0 ?        SN   21:34   0:00 [ksmd]

root         40  0.0  0.0      0     0 ?        S    21:34   0:00 [aio/0]

root         41  0.0  0.0      0     0 ?        S    21:34   0:00 [aio/1]

root         42  0.0  0.0      0     0 ?        S    21:34   0:00 [crypto/0]

root         43  0.0  0.0      0     0 ?        S    21:34   0:00 [crypto/1]

root         48  0.0  0.0      0     0 ?        S    21:34   0:00 [kthrotld/0]

root         49  0.0  0.0      0     0 ?        S    21:34   0:00 [kthrotld/1]

root         50  0.0  0.0      0     0 ?        S    21:34   0:00 [pciehpd]

root         52  0.0  0.0      0     0 ?        S    21:34   0:00 [kpsmoused]

root         53  0.0  0.0      0     0 ?        S    21:34   0:00 [usbhid_resumer]

root         83  0.0  0.0      0     0 ?        S    21:34   0:00 [kstriped]

root        212  0.0  0.0      0     0 ?        S    21:34   0:00 [scsi_eh_0]

root        215  0.0  0.0      0     0 ?        S    21:34   0:00 [scsi_eh_1]

root        227  0.0  0.0      0     0 ?        S    21:34   0:00 [mpt_poll_0]

root        228  0.0  0.0      0     0 ?        S    21:34   0:00 [mpt/0]

root        229  0.0  0.0      0     0 ?        S    21:34   0:00 [scsi_eh_2]

root        344  0.0  0.0      0     0 ?        S    21:34   0:00 [jbd2/sda3-8]

root        345  0.0  0.0      0     0 ?        S    21:34   0:00 [ext4-dio-unwrit]

root        346  0.0  0.0      0     0 ?        S    21:34   0:00 [ext4-dio-unwrit]

root        355  0.0  0.0      0     0 ?        S    21:34   0:00 [flush-8:0]

root        442  0.0  0.5  11196  1280 ?        S<s  21:34   0:00 /sbin/udevd -d

root        624  0.0  0.0      0     0 ?        S    21:34   0:00 [vmmemctl]

root        964  0.0  0.0      0     0 ?        S    21:34   0:00 [kdmflush]

root       1002  0.0  0.0      0     0 ?        S    21:34   0:00 [jbd2/sda1-8]

root       1003  0.0  0.0      0     0 ?        S    21:34   0:00 [ext4-dio-unwrit]

root       1004  0.0  0.0      0     0 ?        S    21:34   0:00 [ext4-dio-unwrit]

root       1005  0.0  0.0      0     0 ?        S    21:34   0:00 [jbd2/dm-0-8]

root       1006  0.0  0.0      0     0 ?        S    21:34   0:00 [ext4-dio-unwrit]

root       1007  0.0  0.0      0     0 ?        S    21:34   0:00 [ext4-dio-unwrit]

root       1050  0.0  0.0      0     0 ?        S    21:34   0:00 [kauditd]

root       1288  0.0  0.4 110464   964 ?        Ssl  21:34   0:00 /usr/sbin/vmware-vmblock

root       1324  0.1  3.1 172376  7256 ?        Sl   21:34   0:06 /usr/sbin/vmtoolsd

root       1385  0.0  4.0  47760  9200 ?        S    21:34   0:00 /usr/lib/vmware-vgauth/V

root       1503  0.0  2.2 203976  5244 ?        Sl   21:34   0:03 /usr/lib/vmware-caf/pme/

root       1687  0.0  0.3  27636   824 ?        S<sl 21:34   0:00 auditd

root       1712  0.0  0.7 249084  1640 ?        Sl   21:34   0:00 /sbin/rsyslogd -i /var/r

rpc        1755  0.0  0.3  18972   912 ?        Ss   21:34   0:00 rpcbind

dbus       1771  0.0  0.5  31784  1200 ?        Ssl  21:34   0:00 dbus-daemon --system

rpcuser    1790  0.0  0.5  23344  1364 ?        Ss   21:34   0:00 rpc.statd

root       1824  0.0  0.0      0     0 ?        S    21:34   0:00 [rpciod/0]

root       1825  0.0  0.0      0     0 ?        S    21:34   0:00 [rpciod/1]

root       1829  0.0  0.2  23088   520 ?        Ss   21:34   0:00 rpc.idmapd

root       1844  0.0  1.4 189192  3316 ?        Ss   21:34   0:00 cupsd -C /etc/cups/cupsd

root       1869  0.0  0.2   4076   644 ?        Ss   21:34   0:00 /usr/sbin/acpid

68         1878  0.0  1.5  25948  3648 ?        Ss   21:34   0:00 hald

root       1879  0.0  0.5  18104  1164 ?        S    21:34   0:00 hald-runner

root       1920  0.0  0.4  20220  1068 ?        S    21:34   0:00 hald-addon-input: Listen

68         1928  0.0  0.4  17804  1032 ?        S    21:34   0:00 hald-addon-acpi: listeni

root       1945  0.0  0.5  64116  1192 ?        Ss   21:34   0:00 /usr/sbin/sshd

root       2111  0.0  1.4  78720  3272 ?        Ss   21:34   0:00 /usr/libexec/postfix/mas

postfix    2118  0.0  1.4  78968  3384 ?        S    21:34   0:00 qmgr -l -t fifo -u

root       2135  0.0  0.4 110172   924 ?        Ss   21:34   0:00 /usr/sbin/abrtd

root       2143  0.0  0.6 117204  1376 ?        Ss   21:34   0:00 crond

root       2154  0.0  0.2  21452   548 ?        Ss   21:34   0:00 /usr/sbin/atd

root       2167  0.0  0.2  61920   580 ?        Ss   21:34   0:00 /usr/sbin/certmonger -S

root       2179  0.0  0.2   4060   532 tty1     Ss+  21:34   0:00 /sbin/mingetty /dev/tty1

root       2181  0.0  0.2   4060   528 tty2     Ss+  21:34   0:00 /sbin/mingetty /dev/tty2

root       2183  0.0  0.2   4060   532 tty3     Ss+  21:34   0:00 /sbin/mingetty /dev/tty3

root       2186  0.0  1.1  12380  2696 ?        S<   21:34   0:00 /sbin/udevd -d

root       2187  0.0  1.1  12380  2696 ?        S<   21:34   0:00 /sbin/udevd -d

root       2188  0.0  0.2   4060   528 tty4     Ss+  21:34   0:00 /sbin/mingetty /dev/tty4

root       2190  0.0  0.2   4060   528 tty5     Ss+  21:34   0:00 /sbin/mingetty /dev/tty5

root       2192  0.0  0.2   4060   528 tty6     Ss+  21:34   0:00 /sbin/mingetty /dev/tty6

root       2207  0.0  1.6  97856  3876 ?        Rs   21:38   0:01 sshd: root@pts/0 

root       2211  0.0  0.8 108432  2012 pts/0    Ss   21:38   0:00 -bash

postfix    2448  0.0  1.4  78800  3228 ?        S    23:13   0:00 pickup -l -t fifo -u

root       2466  1.0  0.4 110232  1128 pts/0    R+   23:26   0:00 ps aux

列出正在运行的所有进程

[root@localhost ~]# ps -elf

F S UID         PID   PPID  C PRI  NI ADDR SZ WCHAN  STIME TTY          TIME CMD

4 S root          1      0  0  80   0 -  4838 poll_s 21:34 ?        00:00:01 /sbin/init

1 S root          2      0  0  80   0 -     0 kthrea 21:34 ?        00:00:00 [kthreadd]

1 S root          3      2  0 -40   - -     0 migrat 21:34 ?        00:00:00 [migration/0]

1 S root          4      2  0  80   0 -     0 ksofti 21:34 ?        00:00:00 [ksoftirqd/0]

1 S root          5      2  0 -40   - -     0 cpu_st 21:34 ?        00:00:00 [migration/0]

5 S root          6      2  0 -40   - -     0 watchd 21:34 ?        00:00:00 [watchdog/0]

1 S root          7      2  0 -40   - -     0 migrat 21:34 ?        00:00:00 [migration/1]

1 S root          8      2  0 -40   - -     0 cpu_st 21:34 ?        00:00:00 [migration/1]

1 S root          9      2  0  80   0 -     0 ksofti 21:34 ?        00:00:00 [ksoftirqd/1]

5 S root         10      2  0 -40   - -     0 watchd 21:34 ?        00:00:00 [watchdog/1]

1 S root         11      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [events/0]

1 S root         12      2  0  80   0 -     0 worker 21:34 ?        00:00:04 [events/1]

1 S root         13      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [cgroup]

1 S root         14      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [khelper]

1 S root         15      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [netns]

1 S root         16      2  0  80   0 -     0 async_ 21:34 ?        00:00:00 [async/mgr]

1 S root         17      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [pm]

1 S root         18      2  0  80   0 -     0 bdi_sy 21:34 ?        00:00:00 [sync_supers]

1 S root         19      2  0  80   0 -     0 bdi_fo 21:34 ?        00:00:00 [bdi-default]

1 S root         20      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [kintegrityd]

1 S root         21      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [kintegrityd]

1 S root         22      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [kblockd/0]

1 S root         23      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [kblockd/1]

1 S root         24      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [kacpid]

1 S root         25      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [kacpi_notif]

1 S root         26      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [kacpi_hotpl]

1 S root         27      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [ata/0]

1 S root         28      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [ata/1]

1 S root         29      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [ata_aux]

1 S root         30      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [ksuspend_us]

1 S root         31      2  0  80   0 -     0 hub_th 21:34 ?        00:00:00 [khubd]

5 S root         32      2  0  80   0 -     0 serio_ 21:34 ?        00:00:00 [kseriod]

1 S root         33      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [md/0]

1 S root         34      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [md/1]

1 S root         35      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [md_misc/0]

1 S root         36      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [md_misc/1]

1 S root         37      2  0  80   0 -     0 watchd 21:34 ?        00:00:00 [khungtaskd]

1 S root         38      2  0  80   0 -     0 kswapd 21:34 ?        00:00:00 [kswapd0]

1 S root         39      2  0  85   5 -     0 ksm_sc 21:34 ?        00:00:00 [ksmd]

1 S root         40      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [aio/0]

1 S root         41      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [aio/1]

1 S root         42      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [crypto/0]

1 S root         43      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [crypto/1]

1 S root         48      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [kthrotld/0]

1 S root         49      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [kthrotld/1]

1 S root         50      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [pciehpd]

1 S root         52      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [kpsmoused]

1 S root         53      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [usbhid_resu]

1 S root         83      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [kstriped]

1 S root        212      2  0  80   0 -     0 scsi_e 21:34 ?        00:00:00 [scsi_eh_0]

1 S root        215      2  0  80   0 -     0 scsi_e 21:34 ?        00:00:00 [scsi_eh_1]

1 S root        227      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [mpt_poll_0]

1 S root        228      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [mpt/0]

1 S root        229      2  0  80   0 -     0 scsi_e 21:34 ?        00:00:00 [scsi_eh_2]

1 S root        344      2  0  80   0 -     0 kjourn 21:34 ?        00:00:00 [jbd2/sda3-8]

1 S root        345      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [ext4-dio-un]

1 S root        346      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [ext4-dio-un]

1 S root        355      2  0  80   0 -     0 bdi_wr 21:34 ?        00:00:00 [flush-8:0]

5 S root        442      1  0  76  -4 -  2799 poll_s 21:34 ?        00:00:00 /sbin/udevd -

1 S root        624      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [vmmemctl]

1 S root        964      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [kdmflush]

1 S root       1002      2  0  80   0 -     0 kjourn 21:34 ?        00:00:00 [jbd2/sda1-8]

1 S root       1003      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [ext4-dio-un]

1 S root       1004      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [ext4-dio-un]

1 S root       1005      2  0  80   0 -     0 kjourn 21:34 ?        00:00:00 [jbd2/dm-0-8]

1 S root       1006      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [ext4-dio-un]

1 S root       1007      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [ext4-dio-un]

1 S root       1050      2  0  80   0 -     0 kaudit 21:34 ?        00:00:00 [kauditd]

1 S root       1288      1  0  80   0 - 27616 futex_ 21:34 ?        00:00:00 /usr/sbin/vmw

4 S root       1324      1  0  80   0 - 43094 poll_s 21:34 ?        00:00:06 /usr/sbin/vmt

0 S root       1385      1  0  80   0 - 11940 poll_s 21:34 ?        00:00:00 /usr/lib/vmwa

1 S root       1503      1  0  80   0 - 50994 hrtime 21:34 ?        00:00:03 /usr/lib/vmwa

5 S root       1687      1  0  76  -4 -  6909 ep_pol 21:34 ?        00:00:00 auditd

5 S root       1712      1  0  80   0 - 62271 poll_s 21:34 ?        00:00:00 /sbin/rsyslog

5 S rpc        1755      1  0  80   0 -  4743 poll_s 21:34 ?        00:00:00 rpcbind

5 S dbus       1771      1  0  80   0 -  7946 poll_s 21:34 ?        00:00:00 dbus-daemon -

5 S rpcuser    1790      1  0  80   0 -  5836 poll_s 21:34 ?        00:00:00 rpc.statd

1 S root       1824      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [rpciod/0]

1 S root       1825      2  0  80   0 -     0 worker 21:34 ?        00:00:00 [rpciod/1]

1 S root       1829      1  0  80   0 -  5772 ep_pol 21:34 ?        00:00:00 rpc.idmapd

4 S root       1844      1  0  80   0 - 47298 ep_pol 21:34 ?        00:00:00 cupsd -C /etc

1 S root       1869      1  0  80   0 -  1019 poll_s 21:34 ?        00:00:00 /usr/sbin/acp

5 S 68         1878      1  0  80   0 -  6487 poll_s 21:34 ?        00:00:00 hald

0 S root       1879   1878  0  80   0 -  4526 poll_s 21:34 ?        00:00:00 hald-runner

0 S root       1920   1879  0  80   0 -  5055 poll_s 21:34 ?        00:00:00 hald-addon-in

4 S 68         1928   1879  0  80   0 -  4451 unix_s 21:34 ?        00:00:00 hald-addon-ac

5 S root       1945      1  0  80   0 - 16029 poll_s 21:34 ?        00:00:00 /usr/sbin/ssh

4 S root       2111      1  0  80   0 - 19680 ep_pol 21:34 ?        00:00:00 /usr/libexec/

4 S postfix    2118   2111  0  80   0 - 19742 ep_pol 21:34 ?        00:00:00 qmgr -l -t fi

1 S root       2135      1  0  80   0 - 27543 poll_s 21:34 ?        00:00:00 /usr/sbin/abr

1 S root       2143      1  0  80   0 - 29301 hrtime 21:34 ?        00:00:00 crond

5 S root       2154      1  0  80   0 -  5363 hrtime 21:34 ?        00:00:00 /usr/sbin/atd

1 S root       2167      1  0  80   0 - 15480 ep_pol 21:34 ?        00:00:00 /usr/sbin/cer

4 S root       2179      1  0  80   0 -  1015 n_tty_ 21:34 tty1     00:00:00 /sbin/mingett

4 S root       2181      1  0  80   0 -  1015 n_tty_ 21:34 tty2     00:00:00 /sbin/mingett

4 S root       2183      1  0  80   0 -  1015 n_tty_ 21:34 tty3     00:00:00 /sbin/mingett

5 S root       2186    442  0  78  -2 -  3095 poll_s 21:34 ?        00:00:00 /sbin/udevd -

5 S root       2187    442  0  78  -2 -  3095 poll_s 21:34 ?        00:00:00 /sbin/udevd -

4 S root       2188      1  0  80   0 -  1015 n_tty_ 21:34 tty4     00:00:00 /sbin/mingett

4 S root       2190      1  0  80   0 -  1015 n_tty_ 21:34 tty5     00:00:00 /sbin/mingett

4 S root       2192      1  0  80   0 -  1015 n_tty_ 21:34 tty6     00:00:00 /sbin/mingett

4 R root       2207   1945  0  80   0 - 24464 -      21:38 ?        00:00:01 sshd: root@pt

4 S root       2211   2207  0  80   0 - 27108 wait   21:38 pts/0    00:00:00 -bash

4 S postfix    2448   2111  0  80   0 - 19700 ep_pol 23:13 ?        00:00:00 pickup -l -t

4 R root       2468   2211  1  80   0 - 27558 -      23:27 pts/0    00:00:00 ps -elf

S列,体现进程的状态(STAT)

R(Running):正在运行

S(Sleep):处于休眠状态,在需要时可唤醒

D:不可中断的休眠,通常为等待I/0的情况

T:停止状态(stop)

Z:(Zombie):僵尸状态,程序已经终止但黑客帝国的内存却未被释放

UID/PID/PPID:进程的拥有者/进程号/父进程号

TTY:启用此里程的终端位置

TIME:消耗的CPU时间

CMD:引发此进程的程序命令行

top 交互式工具

top [-d 刷新秒数(默认3秒)] [-U 用户名]

wKiom1eq3V_CBZ9bAADhGiydSuY462.png

top交互操作 按键指令

?:查看帮助(列出可用的按键指令)

P、M:根据%cpu、%骰降序排列

T:根据进程消耗TIME降序排列

k:杀死指定的进程

q:退出top程序

pgrep Process Grep

-l:输出进程名,而不仅仅是PID

-U:检索指定用户的进程

-t:检索指定终端的进程

[root@localhost ~]# pgrep -l 'vm'

624 vmmemctl

1288 vmware-vmblock-

1324 vmtoolsd

[root@localhost ~]# pgrep -U user1 -t pts/1 -l

2509 bash

进程前 后台调度

前台启动

输入正常的命令行

运行期间占用当前终端

后台启动

在命令行末尾添加 & 符号

运行期间不战胜当前终端

cp /dev/cdrom myiso.iso &

后台制作ISO镜像文件

Ctrl+z 组合键,挂起当前进程(暂停并转入后台),要注意与“&”符号的区别,加“&”是不会暂停的。

jobs 命令:查看后台任务列表。

fg 命令:将后台任务恢复到前台运行。

bg 命令:激活后台被挂起的任务。

crtl+c组合键    中断下在执行的命令程序

杀死进程的命令一般有kill、killall、pkill。

kill:只能针对PID来进行查杀。

killall:可以针对进程名来进行查杀,但进程名字必须是完整的,可以杀死多个。

pkill:可以进行模糊查杀,进程名字可以不写完整。

wKiom1eq4MOg9UR1AAFcEDElCdo392.png

加载BIOS,检查硬件信息

读取并执行第一个开机设备内MBR的Boot Loader

运行grub引导加载kernel

内核启动/sbin/init程序

init 系统初始化

    确定默认的运行级别

    触发runlevel事件,运行/etc/rc.d/rc

    最好后执行/etc/rc.d/rc.local

    加载终端或X-Window接口

linux运行级别

wKioL1eq4ZSADKgIAABwKXaH8z4077.png

[root@localhost ~]# tail -1 /etc/inittab 

id:3:initdefault:

[root@localhost ~]# runlevel

N 3

wKiom1eq4eyDmkBLAACIn39TOA4172.png

/etc/rc.d/rc脚本

rc.conf 调用执行

根据运行级别参数,加载/终止相应服务

/etc/rc.d/rc.local脚本

由rc脚本调用执行

保存用户定义的需开机后自动执行的命令

[root@localhost ~]# vim /etc/rc.local 

#!/bin/sh

#

# This script will be executed *after* all the other init scripts.

# You can put your own initialization stuff in here if you don't

# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local

wKioL1eq4qXAcwdgAABpWXB366Q423.png

原文地址:https://www.cnblogs.com/fina/p/5781808.html