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,395

getting a process tree in conky

i recently discovered the wonders of the ps command in the terminal

i really liked the process tree you can get with pstree.

i would like to get something similar in conky, but i would like to link up each displayed process on the tree with its cpu and mem usage and other info

pstree only shows names

i can do ${exec pstree} in the conky rc

and get this
tNXM0ZA

htop has a tree display along with all the info about particular processes, but it shows everything and isnt nearley as pretty to look at as pstree...
plus if i try and  exec htop in a conkyrc i get only 1 line of info and it is extremely processor intensive!!

i could probably work out some way of displaying processes with info about them in Lua... but I don't know how to arrange them into a tree...

has it got something to do with PID's? or which user the process belongs to?

Anonymous gave me this link in the conky thread
http://www.serice.net/pstree/pstree.awk

but i'm not really understanding what it does smile

just wondering if someone can explain, in relatively easy terms, how a process tree is constructed?
how i determine what process goes where and which processes pstree is not showing that htop shows!

thanks!

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

the tree is contructed by matching pids and ppids (parent pids) as far as i can tell, that seems to be contained in 'group_process_with_its_children()' in your example you posted.
thats basically a recursive function that builds up the tree.
(for a very simple example of how it works on a directory structure http://code.activestate.com/recipes/217 … -structur/ or http://www.siafoo.net/snippet/91, theres probably lua examples around aswell)

sorry for not going into more detail, im sure there are better people on the net at decribing recursion than me, and who know lua to boot.


- - - - - - - - Wiki Pages - - - - - - -
#! install guide           *autostart programs, modify the menu & keybindings
configuring Conky       *installing scripts

Offline

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

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

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,395

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)


- - - - - - - - Wiki Pages - - - - - - -
#! install guide           *autostart programs, modify the menu & keybindings
configuring Conky       *installing scripts

Offline

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

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

Re: getting a process tree in conky

benj1 wrote:

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

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

no fun is being spoiled benj1 big_smile

i've gotta start looking into learning some real coding if i want to get this kind of thing working for me! (whether this actually going to happen or not i don't know so i may just have to continue lamenting about it smile ... but then again why not *goes to look for some lua programming books*)
the way i've been doing it in lua is almost working... i just cant understand why some processes are showing up where they are and breaking the list.
but again, im just working things out based on my own logic smile

i think table manipulations in lua are pretty basic, you have to write your own functions to get things working the way you want
i've seen examples but not completely sure how to use them

i'll keep going however, and see if i cant get it working some time soon, and learn some things in the process (no pun intended)

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.

Debian Logo