daily pastebin goal
62%
SHARE
TWEET

stopall.py

Trinket Jan 31st, 2013 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import subprocess
  2. import signal
  3. import os
  4.  
  5. #Get all proceses owned by group "download"
  6. proc = subprocess.Popen(["ps","-G","download"], bufsize=-1, stdout=subprocess.PIPE)
  7.  
  8. for line in proc.stdout: #Do this for each printed line of the above command
  9.         try:
  10.                 fields = line.split()   #Split the line according to spaces
  11.                 pid = fields[0]         #The first field is the PID of the process (field 4 is the name of it)
  12.                 if int(pid) > 0:        #If its a positive number
  13.                         os.kill(int(pid), signal.SIGSTOP)       #Send SIGSTOP to PID
  14.         except:
  15.                 continue                #If any problem, continue with the next line
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top