sync example

This commit is contained in:
chrys 2017-02-25 01:19:27 +01:00
parent 04816313f8
commit b1fe678fcb

View File

@ -1,19 +1,37 @@
#!/bin/python #!/bin/python
import os import os
import time
start = time.time()
pids = [pid for pid in os.listdir('/proc') if pid.isdigit()] 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: for pid in pids:
try: try:
currStat = open(os.path.join('/proc', pid, 'stat'), 'rb').read() currStat = str(open('/proc/' + pid + '/stat', 'rb').read())
currStat = currStat.split() currStat = currStat.split(' ')
if b'agetty' in currStat[1]: if int(currStat[4]) == 0:
print( currStat ) continue
print(currStat[0]) #print(currStat)
os.major(int(currStat[6])) #print(fg,int(currStat[4]))
os.minor(int(currStat[6])) 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 except IOError: # proc has already terminated
continue continue
print(time.time()-start)
''' '''
Table 1-4: Contents of the stat files (as of 2.6.30-rc7) Table 1-4: Contents of the stat files (as of 2.6.30-rc7)
.............................................................................. ..............................................................................