进程检测与控制(一)

一.认识管道

1.管道是什么

是特殊的文件,叫管道文件,进程之间通讯的一种方式或机制

2.管道分类

(1)匿名管道

没有名字,在bash中用符号"|"表示

(2)命名管道

可以使用mkfifo命令创建管道文件

mkfifo命令创建管道文件

[root@localhost tmp]# mkfifo pfile
[root@localhost tmp]# ll
total 0
prw-r--r--. 1 root root 0 Mar 11 21:36 pfile
[root@localhost tmp]#

3.匿名管道的作用

作用:将上一个命令的输出作为下一个命令的标准输入

[root@localhost tmp]# find /etc/ -size +1M | xargs ls -l
-rw-r--r--. 1 root root 2225495 Mar 4 15:34 /etc/gconf/gconf.xml.defaults/%gconf-tree.xml
-rw-r--r--. 1 root root 8477083 Mar 5 20:37 /etc/selinux/targeted/modules/active/policy.kern
-rw-r--r--. 1 root root 8477083 Mar 5 20:37 /etc/selinux/targeted/policy/policy.24
[root@localhost tmp]#

4.xargs命令的使用

作用:将上一个命令的输出作为下一个命令的参数

[root@localhost tmp]# echo --help|pwd
/tmp
[root@localhost tmp]# echo --help|xargs pwd
Usage: pwd [OPTION]...
Print the full filename of the current working directory.

-L, --logical use PWD from environment, even if it contains symlinks
-P, --physical avoid all symlinks
--help display this help and exit
--version output version information and exit

NOTE: your shell may have its own version of pwd, which usually supersedes
the version described here. Please refer to your shell's documentation
for details about the options it supports.

Report pwd bugs to [email protected]
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils 'pwd invocation'
[root@localhost tmp]#


-n 指定单行显示的从参数个数
-d 定义新的分隔符,默认是空格和换行符

[root@localhost tmp]# cat file
11 22 33 44 55
hello world , so good
I do not think so
[root@localhost tmp]#
[root@localhost tmp]# cat file |xargs -n 3
11 22 33
44 55 hello
world , so
good I do
not think so
[root@localhost tmp]#

二.进程概述

1.什么是进程

进程由程序产生,是正在运行的程序,由自己的生命周期和状态

2.进程的特点

独立性:每一个进程都要自己的私立空间,不被允许时,用户进程无法访问其他进程的地址空间

动态性:系统中正在活动的指令集合

并发性:多个进程可以在单个处理器上并发执行

3.进程的生命周期

三进程信息查看

1.静态查看ps命令

ps -ef
ps -eF
ps aux
ps auxf

案例如下
[root@localhost tmp]# ps -ef |grep vsftpd
root 3409 1 0 11:25 ? 00:00:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
root 8934 7518 0 21:44 pts/1 00:00:00 grep vsftpd

[root@localhost tmp]# ps -eF |grep vsftpd
root 3409 1 0 13033 828 0 11:25 ? 00:00:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
root 8967 7518 0 25833 848 0 21:44 pts/1 00:00:00 grep vsftpd
[root@localhost tmp]#

[root@localhost tmp]# ps aux |head -4
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 19352 1360 ? Ss 11:22 0:02 /sbin/init
root 2 0.0 0.0 0 0 ? S 11:22 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S 11:22 0:00 [migration/0]
[root@localhost tmp]#

猜你喜欢

转载自www.cnblogs.com/golinux/p/10808958.html