Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

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
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/python
  2.  
  3. import os
  4. import subprocess as sp
  5. import sys
  6.  
  7. CHILD = 0
  8.  
  9. def fork_and_execv(path, args=(), verbose=False):
  10.   pid = os.fork()
  11.  
  12.   if pid == CHILD:
  13.     if not args:
  14.         args = (path,)
  15.     if verbose:
  16.       print('execv\'ing: {}{}'.format(path, args))
  17.     os.execv(path, args)
  18.  
  19.   else:
  20.     if verbose:
  21.       print('cpulimit called on PID {}'.format(pid))
  22.     cmd = 'cpulimit -l 1 -p {}'.format(pid)
  23.     sp.call(cmd.split())
  24.  
  25.  
  26. if __name__ == '__main__':
  27.   # Calling list() forces the map to execute
  28.   list(map(lambda x: fork_and_execv(x, verbose=True), sys.argv[1:]))