#!/opt/imh-python/bin/python3
"""Collates and displays useful information on processes in D state"""
with open(f'/proc/{pid}/status', encoding='ascii') as file:
if line.startswith('Uid:'):
"""Get container associated with PID"""
with open(f'/proc/{pid}/stat', encoding='ascii') as file:
return file.read().split()[-1]
"""Grabs the D, jostles it around, and displays it for all to see"""
iznode = os.path.isdir('/etc/vz/')
for pid in [i for i in os.listdir('/proc') if i.isdigit()]:
with open(f'/proc/{pid}/stat', encoding='ascii') as f:
statinfo = f.read().split()[2]
badpids[pid] = {'pid': pid}
badpids[pid]['exe'] = os.readlink('/proc/%s/exe' % pid)
badpids[pid]['uid'] = get_uid(pid)
isnode_output = "%(pid)6s%(uid)6s %(ctid).4s %(exe)-60s"
notnode_output = "%(pid)6s%(uid)6s %(exe)-60s"
output_formatter = isnode_output if iznode else notnode_output
badpids[pid]['ctid'] = get_ctid(pid)
print("\n :: Check Processes in D State ::")
print("\n\n%6s%6s %.4s %s\n" % ('PID', 'UID', 'CTID', 'Executable'))
print("\n\n%6s%6s %s\n" % ('PID', 'UID', 'Executable'))
for pid in sorted(badpids, key=lambda x: int(x)):
print(output_formatter % badpids[pid])
print('\nTotal: %d\n' % len(badpids))