Reputation: 525
I have a list of strings which contains the pid's to certain processes which must be killed at a certain time.
pidList = ['1234', '1235', '1236']
How would one run through the list first casting all elements to int, then killing the process represented by that pid?
essentially doing this:
os.kill(int(pidList[0]), signal.SIGTERM)
os.kill(int(pidList[1]), signal.SIGTERM)
os.kill(int(pidList[2]), signal.SIGTERM)
Upvotes: 1
Views: 1828
Reputation: 7256
you can use list comprehension
[os.kill(int(pid), signal.SIGTERM) for pid in pidlist]
also map will work
map(lambda x: os.kill(int(x), signal.SIGTERM), pidlist)
Upvotes: 0
Reputation: 250941
Simply iterate over the pidlist
for proc_id in pidlist:
os.kill(int(proc_id), signal.SIGTERM)
Upvotes: 3