Advertisement
Trinket

stopall.py

Jan 31st, 2013
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement