【SHELL】使用ps如何准确地打印出某个用户的进程
2015-11-03 11:05
633 查看
请看如下两种方式:
很明显,第一种方式比第二种方式较好。但是第一种方式的19427号进程为什么会被打印出来,目前还不知道。。。。
原因是ps -U 是RUID,正确应该是指定EUID,也就是-u参数。
<pre name="code" class="html"><pre name="code" class="html">[info@localhost ~]$ ps -U 500 -f h info 3964 3962 0 09:47 ? S 0:00 sshd: info@pts/2 info 3965 3964 0 09:47 pts/2 Ss+ 0:00 -bash info 5468 3964 0 10:09 ? Ss 0:00 /usr/libexec/openssh/sftp-server info 5944 1 0 2011 ? Ssl 0:00 /usr/libexec/bonobo-activation-server --ac-activate --ior-output-fd=16 info 6377 6375 0 10:21 ? S 0:00 sshd: info@pts/3 info 6378 6377 0 10:21 pts/3 Ss+ 0:00 -bash info 7068 7066 0 10:32 ? S 0:00 sshd: info@pts/4 info 7069 7068 0 10:32 pts/4 Ss 0:00 -bash info 7740 7069 0 10:43 pts/4 R+ 0:00 ps -U 500 -f h info 19376 19375 0 2012 pts/1 S 0:00 -bash root 19427 19376 0 2012 pts/1 S 0:00 su - root info 26974 1 0 2011 ? Ss 0:00 /home/info/IBM/HTTPServer/bin/httpd -f /home/info/IBM/HTTPServer/conf/admin.conf info 26976 26974 0 2011 ? Sl 0:00 /home/info/IBM/HTTPServer/bin/httpd -f /home/info/IBM/HTTPServer/conf/admin.conf info 29616 26974 0 Sep15 ? Sl 0:00 /home/info/IBM/HTTPServer/bin/httpd -f /home/info/IBM/HTTPServer/conf/admin.conf [info@localhost ~]$ ps -U 500 -f h |wc -l 15 [info@localhost ~]$
[info@localhost ~]$ ps -ef|grep info root 3962 14846 0 09:47 ? 00:00:00 sshd: info [priv] info 3964 3962 0 09:47 ? 00:00:00 sshd: info@pts/2 info 3965 3964 0 09:47 pts/2 00:00:00 -bash info 5468 3964 0 10:09 ? 00:00:00 /usr/libexec/openssh/sftp-server info 5944 1 0 2011 ? 00:00:00 /usr/libexec/bonobo-activation-server --ac-activate --ior-output-fd=16 root 6375 14846 0 10:21 ? 00:00:00 sshd: info [priv] info 6377 6375 0 10:21 ? 00:00:00 sshd: info@pts/3 info 6378 6377 0 10:21 pts/3 00:00:00 -bash root 7066 14846 0 10:32 ? 00:00:00 sshd: info [priv] info 7068 7066 0 10:32 ? 00:00:00 sshd: info@pts/4 info 7069 7068 0 10:32 pts/4 00:00:00 -bash info 7891 7069 0 10:45 pts/4 00:00:00 ps -ef info 7892 7069 0 10:45 pts/4 00:00:00 grep info info 7893 7069 0 10:45 pts/4 00:00:00 more root 19375 19348 0 2012 pts/1 00:00:00 su - info info 19376 19375 0 2012 pts/1 00:00:00 -bash info 26974 1 0 2011 ? 00:00:00 /home/info/IBM/HTTPServer/bin/httpd -f /home/info/IBM/HTTPServer/conf/admin.conf info 26976 26974 0 2011 ? 00:00:00 /home/info/IBM/HTTPServer/bin/httpd -f /home/info/IBM/HTTPServer/conf/admin.conf info 29616 26974 0 Sep15 ? 00:00:00 /home/info/IBM/HTTPServer/bin/httpd -f /home/info/IBM/HTTPServer/conf/admin.conf [info@localhost ~]$ ps -ef|grep info|wc -l 19 [info@localhost ~]$
很明显,第一种方式比第二种方式较好。但是第一种方式的19427号进程为什么会被打印出来,目前还不知道。。。。
原因是ps -U 是RUID,正确应该是指定EUID,也就是-u参数。
[info@localhost ~]$ ps -u 500 -f h info 3964 3962 0 09:47 ? S 0:00 sshd: info@pts/2 info 3965 3964 0 09:47 pts/2 Ss+ 0:00 -bash info 5468 3964 0 10:09 ? Ss 0:00 /usr/libexec/openssh/sftp-server info 5944 1 0 2011 ? Ssl 0:00 /usr/libexec/bonobo-activation-server --ac-activate --ior-output-fd=16 info 6377 6375 0 10:21 ? S 0:00 sshd: info@pts/3 info 6378 6377 0 10:21 pts/3 Ss+ 0:00 -bash info 7068 7066 0 10:32 ? S 0:00 sshd: info@pts/4 info 7069 7068 0 10:32 pts/4 Ss 0:00 -bash info 7740 7069 0 10:43 pts/4 R+ 0:00 ps -U 500 -f h info 19376 19375 0 2012 pts/1 S 0:00 -bash root 19427 19376 0 2012 pts/1 S 0:00 su - root info 26974 1 0 2011 ? Ss 0:00 /home/info/IBM/HTTPServer/bin/httpd -f /home/info/IBM/HTTPServer/conf/admin.conf info 26976 26974 0 2011 ? Sl 0:00 /home/info/IBM/HTTPServer/bin/httpd -f /home/info/IBM/HTTPServer/conf/admin.conf info 29616 26974 0 Sep15 ? Sl 0:00 /home/info/IBM/HTTPServer/bin/httpd -f /home/info/IBM/HTTPServer/conf/admin.conf [info@localhost ~]$ ps -u 500 -f h |wc -l 14 [info@localhost ~]$
相关文章推荐
- linux中shell命令执行的判断依据 &&,||, (),{}
- [Shell]在一个目录及其子目录内的指定类型的文件中搜索某个字符串
- /root/.bashrc与/etc/profile的异同
- [Shell]将字符串转化为大写/小写
- 1.2 使用Hadoop shell命令导入和导出数据到HDFS
- Linux下shell之脚本编写基础
- linux中shell变量$#,$@,$0,$1,$2的含义
- SHELL syntax error:unexpected end of file 提示错误; windows下修改linux文件导致linux文件无法使用
- [转载] shell awk入门
- 判断文件是否存在的shell脚本代码
- Linux_Shell基础
- bash语言学习
- Linux Bash Shell入门教程
- PowerShell 在hyper-v中创建虚拟机
- 解决xshell 中文乱码
- Asp.net使用powershell管理hyper-v
- SHELL脚本 数学运算、数组、文本处理
- C/C++ ShellExecuteEx调用exe可执行文件
- C/C++ ShellExecuteEx调用exe可执行文件
- SHELL脚本基础