[pyar] ps aux | grep process_name en python?

Claudio Freire klaussfreire en gmail.com
Mie Jun 27 15:53:26 ART 2012


2012/6/27 DF-- <dj.foguelman en gmail.com>:
> Alguna idea q no invulucre llamar a subprocess?

>>> import re
>>> matcher = re.compile('bash.*')
>>> filter(str.isdigit,os.listdir('/proc'))
['1', '2', '3', '6', '7', '8', '10', '12', '13', '15', '16', '17',
'19', '20', '21', '23', '24', '25', '26', '27', '28', '29', '31',
'32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42',
'43', '44', '45', '46', '47', '48', '49', '156', '159', '160', '163',
'164', '165', '166', '167', '168', '172', '173', '175', '176', '177',
'180', '182', '223', '224', '305', '419', '483', '909', '910', '911',
'912', '913', '914', '915', '916', '917', '1170', '1207', '1238',
'1243', '1245', '1252', '1495', '1531', '1556', '1581', '1605',
'1614', '1661', '1717', '1745', '1746', '1799', '1806', '1807',
'1812', '1880', '1926', '2003', '2008', '2014', '2066', '2218',
'2311', '2375', '2399', '2413', '2414', '2415', '2416', '2697',
'2786', '2789', '2809', '2824', '2865', '2874', '2875', '2876',
'2877', '2878', '2879', '2886', '2996', '2997', '4382', '4383',
'4442', '4457', '4474', '4517', '4520', '4521', '4528', '4535',
'4543', '4549', '4554', '4559', '4561', '4563', '4566', '4569',
'4575', '4578', '4579', '4580', '4581', '4582', '4584', '4587',
'4590', '4593', '4601', '4605', '4628', '4629', '4632', '4634',
'4647', '4650', '4666', '4668', '4686', '4706', '4812', '4817',
'4818', '4825', '4831', '4836', '4842', '4847', '4889', '4890',
'4893', '6285', '6349', '6351', '6354', '6374', '6378', '6381',
'6398', '6557', '6688', '6780', '6822', '7721', '7820', '8026',
'12658', '12860', '13510', '13774', '13872', '13875', '13996',
'13998', '14046']
>>> def cmdmatch(x):
...    return matcher.match(open('/proc/%s/cmdline' % x,'r').read())
...
>>> filter(cmdmatch,filter(str.isdigit,os.listdir('/proc')))
['6822', '8026', '12860', '13875']



More information about the pyar mailing list