免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1427 | 回复: 1
打印 上一主题 下一主题

a Python version of "pidof" on Solaris [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-08-31 00:06 |只看该作者 |倒序浏览
I copied from other place and it's a very useful tool.

=================================================
#!/usr/bin/env python
import os
import sys
import re

if len(sys.argv) != 2:
    #print >> sys.stderr, "Provide one (and one only) pattern to match."
    sys.exit(1)

ps = os.popen('ps -e')

ps.readline() #-- To eliminate initial line
for line in ps:
    try:
        match = re.search(r"%s" % (sys.argv[1],), line, re.IGNORECASE)
    except re.error:
        match = None
        sys.exit(1)
    if match != None:
        print re.search(r"^\s*?(\d+)(?=\s)", line).group(1)

论坛徽章:
0
2 [报告]
发表于 2006-08-31 12:05 |只看该作者
我觉得这样就可以满足需要了。

bash-2.05$ more ~/perl/pidof
#!/bin/sh
if [ $# -ne 1 ]
then
echo "usage: $0 yourcommand"
exit 1
fi
ps -A | grep $1 | awk '{print $1}'
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP