From 3975329a2e321ab52830407869f8ab905b40eb73 Mon Sep 17 00:00:00 2001 From: YustasGals <31280025+YustasGals@users.noreply.github.com> Date: Thu, 12 Apr 2018 19:24:05 +0300 Subject: [PATCH 1/8] Update README.md add SVN option --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index dd25882..0b61f1e 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,16 @@ Generate graph: ````shell sudo lsof -n -F | python lsofgraph.py | dot -Tjpg > /tmp/a.jpg + OR +sudo lsof -n -F | python lsofgraph.py | dot -T svg > /tmp/a.svg ```` or add `unflatten` to the chain for a better layout: ````shell sudo lsof -n -F | python lsofgraph.py | unflatten -l 1 -c 6 | dot -T jpg > /tmp/a.jpg + OR +sudo lsof -n -F | python lsofgraph.py | unflatten -l 1 -c 6 | dot -T svg > /tmp/a.svg ```` ![example output](/example.jpg) From a9bb82870e62f3b9872edfdfcb9c82d396dba457 Mon Sep 17 00:00:00 2001 From: akme Date: Thu, 12 Apr 2018 21:25:43 +0300 Subject: [PATCH 2/8] fixed unnecessary items copy --- lsofgraph.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lsofgraph.py b/lsofgraph.py index c9503c1..e70bdca 100644 --- a/lsofgraph.py +++ b/lsofgraph.py @@ -149,12 +149,12 @@ def print_graph(procs, conns): print("\tp%s [ label = \"%s\\n%s %s\" fillcolor=%s ];" % (proc['p'], proc['n'], proc['p'], proc['L'], color)) elif 'p' in proc: - if 'L' in proc: # there could be no L flag if process running, but user was removed. lsof: no pwd entry for UID + if 'L' in proc: # there could be no L flag if process running, but user was removed. lsof: no pwd entry for UID print("\tp%s [ label = \"%s\\n%s %s\" fillcolor=%s ];" % - (proc['p'], proc['c'], proc['p'], proc['L'], color)) + (proc['p'], proc['c'], proc['p'], proc['L'], color)) else: print("\tp%s [ label = \"%s\\n%s %s\" fillcolor=%s ];" % - (proc['p'], proc['c'], proc['p'], "no user", color)) + (proc['p'], proc['c'], proc['p'], "no user", color)) if 'R' in proc and proc['R'] in procs: proc_parent = procs[proc['R']] if proc_parent: @@ -163,7 +163,7 @@ def print_graph(procs, conns): "\tp%s -> p%s [ penwidth=2 weight=100 color=grey60 dir=\"none\" ];" % (proc['R'], proc['p'])) for type, conn in conns.iteritems(): - for id, files in conn.items(): + for id, files in conn.iteritems(): if len(files) == 2: if files[0]['proc'] != files[1]['proc']: label = type + ":\\n" + id From 21ebd3e3096d85f7040e9920d64820de82d6e0d1 Mon Sep 17 00:00:00 2001 From: Valerii Kravets Date: Mon, 16 Apr 2018 16:09:23 +0300 Subject: [PATCH 3/8] Add mac OS to Readme.md --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 0b61f1e..c705888 100644 --- a/README.md +++ b/README.md @@ -19,3 +19,13 @@ sudo lsof -n -F | python lsofgraph.py | unflatten -l 1 -c 6 | dot -T svg > /tmp/ ```` ![example output](/example.jpg) + +#Install and use to Mac OS + +Graphviz contains utilities dot and unflatten +````shell +brew install Graphviz +git clone https://github.com/akme/lsofgraph-python.git +cd lsofgraph-python +lsof -n -F | python lsofgraph.py | unflatten -l 1 -c 6 | dot -T jpg > /tmp/a.jpg && open /tmp/a.jpg +```` From 265c22ed9f4a0647a3cd2a402e8d8e80f1926f5b Mon Sep 17 00:00:00 2001 From: viniokil <31795742+viniokil@users.noreply.github.com> Date: Mon, 16 Apr 2018 16:11:43 +0300 Subject: [PATCH 4/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c705888..8847889 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ sudo lsof -n -F | python lsofgraph.py | unflatten -l 1 -c 6 | dot -T svg > /tmp/ ![example output](/example.jpg) -#Install and use to Mac OS +# Install and use to Mac OS Graphviz contains utilities dot and unflatten ````shell From e2635c2aef094659b40a80915ed139148b898475 Mon Sep 17 00:00:00 2001 From: viniokil <31795742+viniokil@users.noreply.github.com> Date: Mon, 16 Apr 2018 16:47:49 +0300 Subject: [PATCH 5/8] Update README.md Add svg pipe --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 8847889..09b87de 100644 --- a/README.md +++ b/README.md @@ -28,4 +28,5 @@ brew install Graphviz git clone https://github.com/akme/lsofgraph-python.git cd lsofgraph-python lsof -n -F | python lsofgraph.py | unflatten -l 1 -c 6 | dot -T jpg > /tmp/a.jpg && open /tmp/a.jpg +lsof -n -F | python lsofgraph.py | unflatten -l 1 -c 6 | dot -T svg > /tmp/a.jpg && open -a Safari.app '/tmp/a.svg' ```` From ca0d375fad2d2224306705442ebebefdf50b03e3 Mon Sep 17 00:00:00 2001 From: akme Date: Fri, 9 Nov 2018 07:57:03 +0300 Subject: [PATCH 6/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 09b87de..f6f70a8 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ sudo lsof -n -F | python lsofgraph.py | unflatten -l 1 -c 6 | dot -T svg > /tmp/ ![example output](/example.jpg) -# Install and use to Mac OS +# Install and use on MacOS Graphviz contains utilities dot and unflatten ````shell From f187fb05798b95a72401ce2ec89be16a53f750c1 Mon Sep 17 00:00:00 2001 From: sandlekang Date: Tue, 21 Feb 2023 12:27:43 +0900 Subject: [PATCH 7/8] python3 compatibility update --- lsofgraph.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lsofgraph.py b/lsofgraph.py index e70bdca..4b88f3a 100644 --- a/lsofgraph.py +++ b/lsofgraph.py @@ -12,7 +12,7 @@ def parse_lsof(): for line in sys.stdin: if line.startswith("COMMAND"): - print 'did you run lsof without -F?' + print("did you run lsof without -F?") exit(1) tag = line[0] @@ -54,7 +54,7 @@ def find_connections(procs): 'udp': {}, 'pipe': {} } - for pid, proc in procs.iteritems(): + for pid, proc in procs.items(): if 'files' in proc: for _, file in enumerate(proc['files']): @@ -140,7 +140,7 @@ def print_graph(procs, conns): # Parent/child relationships - for pid, proc in procs.iteritems(): + for pid, proc in procs.items(): if 'R' in proc and proc['R'] == "1": color = "grey70" else: @@ -162,8 +162,8 @@ def print_graph(procs, conns): print( "\tp%s -> p%s [ penwidth=2 weight=100 color=grey60 dir=\"none\" ];" % (proc['R'], proc['p'])) - for type, conn in conns.iteritems(): - for id, files in conn.iteritems(): + for type, conn in conns.items(): + for id, files in conn.items(): if len(files) == 2: if files[0]['proc'] != files[1]['proc']: label = type + ":\\n" + id From 56764c6b85f7159f0483b9a709c15f868f6b2001 Mon Sep 17 00:00:00 2001 From: Daniel Apatin Date: Fri, 14 Jun 2024 17:22:42 +0300 Subject: [PATCH 8/8] Fix maximum recursion depth exceeded error --- README.md | 2 +- lsofgraph.py | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f6f70a8..85e1da4 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,6 @@ sudo lsof -n -F | python lsofgraph.py | dot -Tjpg > /tmp/a.jpg OR sudo lsof -n -F | python lsofgraph.py | dot -T svg > /tmp/a.svg ```` - or add `unflatten` to the chain for a better layout: ````shell @@ -17,6 +16,7 @@ sudo lsof -n -F | python lsofgraph.py | unflatten -l 1 -c 6 | dot -T jpg > /tmp/ OR sudo lsof -n -F | python lsofgraph.py | unflatten -l 1 -c 6 | dot -T svg > /tmp/a.svg ```` +Note: In cases of handling large datasets, you might encounter a "maximum recursion depth exceeded" error. To work around this, you can increase the recursion limit in your Python environment by adding `sys.setrecursionlimit(15000)` in the `lsofgraph.py` script. ![example output](/example.jpg) diff --git a/lsofgraph.py b/lsofgraph.py index 4b88f3a..b9368ad 100644 --- a/lsofgraph.py +++ b/lsofgraph.py @@ -178,6 +178,10 @@ def print_graph(procs, conns): if __name__ == '__main__': - procs = parse_lsof() - conns = find_connections(procs) - print_graph(procs, conns) + sys.setrecursionlimit(15000) # Increase the recursion limit before processing starts + try: + procs = parse_lsof() + conns = find_connections(procs) + print_graph(procs, conns) + except RuntimeError as e: + print("Error: Recursion depth exceeded. Consider increasing the recursion limit.")