Created
February 26, 2016 00:59
-
-
Save t94j0/917e773b692556eaa8b2 to your computer and use it in GitHub Desktop.
Checks for new processes created in a specified period of time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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