首页 » Linux » Linux学习笔记六[进程管理和系统服务]

Linux学习笔记六[进程管理和系统服务]

第七章  进程管理与系统服务

7.1 进程的管理

进程的类型
1.可以将运行在Linux系统中的进程分为三种不同的类型:
2.交互进程:由一个Shell启动的进程。交互进程既可以在前台运行,也可以在后台运行。
3.批处理进程:不与特定的终端相关联,提交到等待队列种顺序执行的进程。
守护进程:在Linux在启动时初始化,需要时运行于后台的进程。
命令1: top 系统监控 5s更新一次
按u输入用户名   查看用户进程
按k键:输入PID  删除进程
R    renice

命令2: ps  查看系统进程

a 显示所有用户的所有进程(包括其它用户);
u 按用户名和启动时间的顺序来显示进程;
x 显示无控制终端的进程;
[root@centmini ~]# ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.1  0.3   2064   628 ?        Ss   09:35   0:00 init [3]             

…                   
root         2  0.0  0.0      0     0 ?        S<   09:35   0:00 [migration/0]
root         3  0.0  0.0      0     0 ?        SN   09:35   0:00 [ksoftirqd/0]

[root@centmini ~]# ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 09:35 ?        00:00:00 init [3]

Tips: 不要使用 ps –aux  ,使用ps aux
ps aux[BSD style]   ps -ef[System V Style]

命令3: kill   杀死进程  -9 强制杀死
命令4: nice和renice  优先级修改【-20到19】
nice 设置优先级并运行
renice 修改已运行程序的优先级
   nice –n 5 top
renice -5 –u Linda 

命令5: pstree  显示进程树状结构

命令6: pgrep gnome       pgrep –u linda
 

7.2 进程的挂起与恢复

进程的中止(挂起)和终止
挂起(Ctrl+Z)
终止(Ctrl+C)

进程的恢复
恢复到前台继续运行(fg)
恢复到后台继续运行(bg)

查看被挂起的进程(jobs)

 

7.3 计划任务

7.3.1 at定时服务(服务进程atd)

检查是否安装,和是否开启
[root@centmini ~]# rpm -q at
at-3.1.8-82.fc6
[root@centmini ~]# service atd status
atd is stopped
[root@centmini ~]# chkconfig –list atd
开启 使用 和查看队列和删除任务
[root@centmini ~]# service atd start
Starting atd: [  OK  ]
[root@centmini ~]# at 22:30
at> poweroff
at> <EOT>
job 1 at 2009-09-28 22:30
[root@centmini ~]# atq
1 2009-09-28 22:30 a root
[root@centmini ~]# atrm 1
[root@centmini ~]# atq
[root@centmini ~]#
at服务的访问控制
/etc/at.allow 和/etc/at.deny
如果at.allow存在,只有设置在at.allow中的用户可以使用
如果at.allow不存在,at.deny存在,只有不在at.deny中的用户可以使用。
如果都不存在,只有超级用户可以使用。

If  the file  /etc/at.allow exists, only usernames mentioned in it are allowed to use at.
If /etc/at.allow does not exist, /etc/at.deny is checked.

CentOS5.3默认存在at.deny没有at.allow.
Note: Performing just the at command at the prompt will give you an error “Garbled Time”, this is a standard error message if no switch or time setting is given.

只在提示符后输入at命令,会出现Garbled time 的提示,这里要求必须输入时间。

7.3.2  cron执行服务

首先应查看运行状态,软件包vixie-cron 服务名crond
[root@centmini ~]# rpm -q vixie-cron
vixie-cron-4.1-76.el5
[root@centmini ~]# service crond status
crond (pid 1547) is running…

corn数据文件
格式:
MIN HOUR DAY MONTH DayOfWeek COMMANDS
范例:
20 4 * * * program
 指定每天的4点20分执行program命令
50 3 9 * * program
指定每月的9日3点50分执行program命令
1 0 8 9 * program 或
1 0 8 sep * program

crons数据文件的使用

1. 输入数据文件  crontab XXX
2. 查看  crontab -l
3. 修改  crontab –e
4. 删除  crontab -r
[root@centmini ~]# cat mycron
10 3 18 5 1 echo “Now is Monday.XXX”

[root@centmini ~]# crontab mycron
[root@centmini ~]# crontab -l
10 3 18 5 1 echo “Now is Monday.XXX”

[root@centmini ~]# crontab –e
[root@centmini ~]# crontab -r
cron的访问控制
/etc/cron.allow和/etc/cron.deny使用方法和at的一致。

队列位置/var/spool/cron

配置文件/etc/crontab

 

7.4 系统日志服务

日志系统3大组件:klogd内核日志,syslogd系统日志,logger客户端工具。

软件包sysklogd  服务名syslog
[root@centmini etc]# service syslog status
syslogd (pid 1433) is running…
klogd (pid 1436) is running…
日志系统配置文件
[root@centmini etc]# cat /etc/syslog.conf
# Log all kernel messages to the console.
# Logging much else clutters up the screen.
#kern.*             /dev/console

# Log anything (except mail) of level info or higher.
# Don’t log private authentication messages!
*.info;mail.none;authpriv.none;cron.none    /var/log/messages

# The authpriv file has restricted access.
authpriv.*         /var/log/secure
格式:设备.级别   动作

日志存放目录位置/var/log/

集中式日志服务(日志服务器)

 

7.5 系统服务的管理

按照启动方式分为Standalone和Super Daemon

7.5.1 Stand alone服务管理

  /etc/rc.d/init.d     /etc/init.d 【LSB标准】-> /etc/rc.d/init.d

使用方法:/etc/rc.d/init.d/sshd [start|stop|restart|reload|status]
          service sshd  [start|stop|restart|reload|status]

独立系统服务的启动

A 直接嵌入runlevel目录
个文件夹分别代表各个运行级别

如下例:K开头表示结束服务,S开又表示开启服务
[root@centmini ~]# ll /etc/rc.d
total 112
drwxr-xr-x 2 root root  4096 Sep 24 21:50 init.d
-rwxr-xr-x 1 root root  2255 Nov 13  2008 rc
drwxr-xr-x 2 root root  4096 Sep 24 21:50 rc0.d
drwxr-xr-x 2 root root  4096 Sep 24 21:50 rc1.d

drwxr-xr-x 2 root root  4096 Sep 24 21:50 rc6.d
-rwxr-xr-x 1 root root   220 Nov 13  2008 rc.local
-rwxr-xr-x 1 root root 27420 Mar  5  2009 rc.sysinit
[root@centmini ~]# ls /etc/rc.d/rc3.d

B使用chkconfig

chkconfig –list  XX查看某服务状态
chkconfig [--add|--del] STARTUPFILE 注册和删除
chkconfig –level X STARTUPFILE [on | off | reset]
[root@www ~]# chkconfig –level 345 atd on
7.5.2 SuperDaemon的管理
SuperDaemon由xinnetd管理。先确认是否安装。CentOS 5默认没有安装。

xinetd的配置文件/etc/xinnetd.conf   /etc/xinetd.d/目录

[root@centmini xinetd.d]# cat rsync
# default: off
service rsync
{
        disable = yes
        socket_type     = stream
        wait            = no
        user            = root
disable=no 即可开启

刷新xinetd的调用
service xinetd reload

使用chkconfig管理服务
基于 xinetd 的服务,无需设定运行级别

chkconfig XXX [on | off]

 

7.5.3 其他的服务管理工具
A  ntsysv
使用方法:ntsysv –level X 不加参数,编辑的是当前运行级别
B system-config-services 图形方式管理

, , , ,

目前这篇文章还没有评论(Rss)

我要评论

icon_wink.gif icon_neutral.gif icon_mad.gif icon_twisted.gif icon_smile.gif icon_eek.gif icon_sad.gif icon_rolleyes.gif icon_razz.gif icon_redface.gif icon_surprised.gif icon_mrgreen.gif icon_lol.gif icon_idea.gif icon_biggrin.gif icon_evil.gif icon_cry.gif icon_cool.gif icon_arrow.gif icon_confused.gif icon_question.gif icon_exclaim.gif 

*
请输入图片中的字符以验证你并非垃圾机器人. 点击图片收听验证码的语音版.
点击这里收听此验证码的语音版本