Skip to content

Instantly share code, notes, and snippets.

@t94j0
Created February 26, 2016 00:59
Show Gist options
  • Save t94j0/917e773b692556eaa8b2 to your computer and use it in GitHub Desktop.
Save t94j0/917e773b692556eaa8b2 to your computer and use it in GitHub Desktop.
Checks for new processes created in a specified period of time
#!/use/bin/python3
from time import sleep
import psutil #pip install psutil
import sys
def main():
final = []
seconds = 1
if len(sys.argv) == 2:
seconds = int(sys.argv[1])
init_procs = psutil.pids()
for x in range(seconds):
sleep(1)
new_procs = psutil.pids()
different_procs = [proc for proc in new_procs if proc not in init_procs]
for proc in different_procs:
p = psutil.Process(proc)
final.append("{} {} {}".format(p.exe(), p.open_files(), p.environ()))
init_procs.append(different_procs)
for x in final:
print("{}\n\n".format(x))
pass
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment