Wie füge ich jedem Knoten in Graphviz eine Beschriftung hinzu?

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Wie füge ich jedem Knoten in Graphviz eine Beschriftung hinzu?

by Anonymous » 26 Aug 2025, 10:39

[bearbeiten] Wie hier gefragt ist, was ps < /code> für mich tut: < /p>

Code: Select all

   PID TTY          TIME CMD
3796 pts/0    00:00:00 bash
4811 pts/0    00:00:00 ps
< /code>

Ich beginne mit GraphViz und möchte den Namen des laufenden Vorgangs anzeigen. Ich habe ein Skript, das ihre Nummer anzeigt, und versuche, jedem Knoten ein Etikett hinzuzufügen. < /p>

Das [url=viewtopic.php?t=26065]Problem[/url] ist, dass nur die letzte Schreibkennzeichnung < /code> auf den Stammknoten angezeigt wird. Wie kann ich es schaffen, ein Etikett an jeden Knoten zu schreiben?#!/usr/bin/env python3

from subprocess import Popen, PIPE, call
import re

dot = open("psgraph.dot", "w")
dot.write("digraph G {\n")

p = Popen("ps -fe", shell=True, stdout=PIPE)
psre = re.compile(r"\w+\s+(\d+)\s+(\d+)")

p.stdout.readline() # ignore first line
for line in p.stdout:
match = psre.search(line.decode("utf-8"))
if match:
if int(match.group(2)) in (0, 2):
continue
dot.write ("  {1} -> {0}\n".format(match.group(1), match.group(2)))

for line in p.stdout:
match = psre.search(line.decode("utf-8"))
if match:
if int(match.group(2)) in (0, 2):
continue
dot.write ("""1 [label="loop"]\n""")

dot.write("""1 [label="laste write"]}\n""")
dot.close()

call("dot -Tpdf -O psgraph.dot", shell=True)

Top