Created
January 25, 2018 16:08
-
-
Save manics/f51afa3b924d80980ea9de779ad8b353 to your computer and use it in GitHub Desktop.
Parse the output of `lsof -F`
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
#!/usr/bin/env python | |
# Convert the output of `lsof -F` into PID USER CMD OBJ | |
import sys | |
rs = [] | |
pid = -1 | |
cmd = '' | |
user = '' | |
for line in sys.stdin: | |
k = line[0] | |
v = line[1:].rstrip('\n') | |
if k == 'p': | |
pid = int(v) | |
user = '' | |
cmd = '' | |
if k == 'L': | |
user = v | |
if k == 'c': | |
cmd = v | |
if k == 'n': | |
obj = v | |
print('%d\t%s\t%s\t%s' % (pid, user, cmd, obj)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment