One Request Answered in the Affirmative.
By: a guest on
Jun 2nd, 2014 | syntax:
Python | size: 0.60 KB | views:
161 | expires: in 29 days
#!/usr/bin/python
import os
import subprocess as sp
import sys
CHILD = 0
def fork_and_execv(path, args=(), verbose=False):
pid = os.fork()
if pid == CHILD:
if not args:
args = (path,)
if verbose:
print('execv\'ing: {}{}'.format(path, args))
os.execv(path, args)
else:
if verbose:
print('cpulimit called on PID {}'.format(pid))
cmd = 'cpulimit -l 1 -p {}'.format(pid)
sp.call(cmd.split())
if __name__ == '__main__':
# Calling list() forces the map to execute
list(map(lambda x: fork_and_execv(x, verbose=True), sys.argv[1:]))