SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2010-10-11 22:57:26

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

getting a process tree in conky

Offline

Help fund CrunchBang, donate to the project!

#2 2010-10-12 19:50:34

benj1
Wiki Wizard
From: Yorkshire, England
Registered: 2009-09-05
Posts: 1,084

Re: getting a process tree in conky

Offline

#3 2010-10-13 03:52:41

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: getting a process tree in conky

Thanks Benj1!

I will try and search some Lua code out smile
but I have a feeling this project goes a little too far beyond my coding skills!

Offline

#4 2010-10-13 07:12:54

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: getting a process tree in conky

well, I think im getting there, although currently stuck... very late and brain going numb!

this code in lua

pid=conky_parse("${exec ps -eo pid --sort=ppid}")
pid=string.gsub(pid, " ", "")
pid=string.split(pid, "")
ppid=conky_parse("${exec ps -eo ppid --sort=ppid}")
ppid=string.gsub(ppid, " ", "")
ppid=string.split(ppid, "")
name=conky_parse("${exec ps -eo comm --sort=ppid}")
name=string.gsub(name, " ", "")
name=string.split(name, "")

number=table.maxn(name)

test={}
for i=1,number do
b=i
for i=1,number do
if ppid[b]==pid[i] then
n=i
end
end
test[b]=n
end

number=table.maxn(test)

for i=1,number do
x=i
print (pid[test[x]], pid[x] )
end

gives me this output

init    udevd
init    mount.ntfs-3g
init    getty
init    getty
init    getty
init    getty
init    getty
init    acpid
init    syslogd
init    dd
init    klogd
init    dbus-daemon
init    exim4
init    hald
init    console-kit-dae
init    gdm
init    NetworkManager
init    wpa_supplicant
init    nm-system-setti
init    avahi-daemon
init    cupsd
init    system-tools-ba
init    atd
init    cron
init    getty
init    lxsession
init    dbus-daemon
init    dbus-launch
init    python
init    gconfd-2
init    gam_server
init    gnome-power-man
init    gvfsd
init    gnome-screensav
init    notification-da
init    lxsession
init    gvfs-hal-volume
init    gvfs-gphoto2-vo
kthreadd    migration/0
kthreadd    ksoftirqd/0
kthreadd    watchdog/0
kthreadd    events/0
kthreadd    khelper
kthreadd    kstop/0
kthreadd    kintegrityd/0
kthreadd    kblockd/0
kthreadd    kacpid
kthreadd    kacpi_notify
kthreadd    cqueue
kthreadd    ata/0
kthreadd    ata_aux
kthreadd    ksuspend_usbd
kthreadd    khubd
kthreadd    kseriod
kthreadd    kmmcd
kthreadd    btaddconn
kthreadd    btdelconn
kthreadd    pdflush
kthreadd    pdflush
kthreadd    kswapd0
kthreadd    aio/0
kthreadd    ecryptfs-kthrea
kthreadd    scsi_eh_0
kthreadd    scsi_eh_1
kthreadd    kstriped
kthreadd    kmpathd/0
kthreadd    kmpath_handlerd
kthreadd    ksnapd
kthreadd    kondemand/0
kthreadd    krfcommd
kthreadd    kjournald
kthreadd    scsi_eh_2
kthreadd    usb-storage
hald    hald-runner
hald-runner    hald-addon-usb-
hald-runner    hald-addon-inpu
hald-runner    hald-addon-stor
hald-runner    hald-addon-stor
hald-runner    hald-addon-stor
hald-runner    hald-addon-acpi
gdm    gdm
gdm    Xorg
gdm    openbox
NetworkManager    dhclient
conky_start2    conky
conky    sh
avahi-daemon    avahi-daemon
avahi-daemon    ps
openbox    ssh-agent
openbox    lxsession
openbox    volwheel
openbox    xcompmgr-crunch
openbox    nm-applet
openbox    tint2
openbox    thunar
openbox    firefox
openbox    gedit
openbox    /usr/bin/termin
openbox    /usr/bin/termin
volwheel    perl
xcompmgr-crunch    xcompmgr
/usr/bin/termin    gnome-pty-helpe
/usr/bin/termin    bash
bash    conky_start2
/usr/bin/termin    gnome-pty-helpe
/usr/bin/termin    bash
/usr/bin/termin    COMMAND
/usr/bin/termin    init
/usr/bin/termin    kthreadd

this is by sorting the output of ps by ppid number... but as you can see some of the processes and their parents have been separated by other processes

but if i can sort that out and figure a way of turning theis output into something that looks half way decent... then i can get cpu% and mem% from similar ps commands to go along with each process

Last edited by mrpeachy (2010-10-13 07:20:58)

Offline

#5 2010-10-14 20:18:38

benj1
Wiki Wizard
From: Yorkshire, England
Registered: 2009-09-05
Posts: 1,084

Re: getting a process tree in conky

I've been thinking about this too, its actually quite tricky ive got something working in python tho
its using a madeup dataset but ps -oe pid,ppid,comm run through a couple of filters should get your data the way you want

#! /usr/bin/python
def tree( procs, padding, startpid):
  padding = padding + ' ' 
  for proc in procs: #loop through processes
    if proc[0] == startpid: #proc[0] = pid, proc[1] = ppid, proc[2] = proc name
      print padding + '|'
      print padding + '+-' + proc[2]
      children = haschildren(proc[0], procs) #see below
      for ch in children:
        pid = ch[0]
        tree(procs, padding + '|', pid) #and repeat

def haschildren(pid,proclist):
  chlist = []
  for l in proclist:
    if pid == l[1]:
      chlist += [l]
  return chlist #return list of children

#made up data set [pid,ppid,process name]
proc=[
[1,0,'init'],
[2,1,'foo'],
[3,1,'bar'],
[10,3,'barr'],
[11,3,'barrrr'],
[12,2,'fooo']
]
      
tree(proc, '', 1) 

I don't know lua but this should be transferable, 'proc' is just a 2D list which exist in lua (i think).

anyway ill stop spoiling your fun tongue

Last edited by benj1 (2010-10-14 20:19:24)

Offline

#6 2010-10-15 01:49:24

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: getting a process tree in conky

Last edited by mrpeachy (2010-10-15 01:57:23)

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.
Server: bleh

Debian Logo