From b1fe678fcba5049c1f9a00a76d2fa8d9de9c2d19 Mon Sep 17 00:00:00 2001 From: chrys Date: Sat, 25 Feb 2017 01:19:27 +0100 Subject: [PATCH] sync example --- play zone/parseProcessTree.py | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/play zone/parseProcessTree.py b/play zone/parseProcessTree.py index 634cfc7c..1303f46e 100644 --- a/play zone/parseProcessTree.py +++ b/play zone/parseProcessTree.py @@ -1,19 +1,37 @@ #!/bin/python import os +import time +start = time.time() pids = [pid for pid in os.listdir('/proc') if pid.isdigit()] +#pids = ['5960'] +tty = os.open('/dev/tty2', os.O_RDWR) +fg = str(os.tcgetpgrp(tty)) +tty.close() +print(fg) for pid in pids: try: - currStat = open(os.path.join('/proc', pid, 'stat'), 'rb').read() - currStat = currStat.split() - if b'agetty' in currStat[1]: - print( currStat ) - print(currStat[0]) - os.major(int(currStat[6])) - os.minor(int(currStat[6])) + currStat = str(open('/proc/' + pid + '/stat', 'rb').read()) + currStat = currStat.split(' ') + if int(currStat[4]) == 0: + continue + #print(currStat) + #print(fg,int(currStat[4])) + if fg == currStat[4]: + print(currStat[1]) + #print( currStat ) + #print(currStat[0]) + major = os.major(int(currStat[6])) + minor = os.minor(int(currStat[6])) + ueventContent = open('/sys/dev/char/' + str(major) + ':' + str(minor) + '/uevent','r').read().split() + #print(ueventContent) + #print(int(currStat[4]),currStat[1]) except IOError: # proc has already terminated continue - + +print(time.time()-start) + + ''' Table 1-4: Contents of the stat files (as of 2.6.30-rc7) ..............................................................................