Though Xdialog doesn't have a multicolumn list function and seems ill equipped for the task it's possible. Processes are sorted by starting time and also show their status (zombies would show as 'Z'). Some properties (the important PPID and the sometimes lengthy ARGS) are difficult to display in the main list and therefore went into the help line at the bottom, which functions like a tooltip.
So far, so good. Still I was puzzled when I saw the result. The script takes the output of the ps command, pipes it to sort and then to awk. What I still don't understand: When ps outputs a list of current processes, the following sort and awk processes haven't started yet. How can they be already included in the list? Trying to kill them results in an error since - like zombies - they are already dead.
I can avoid such deadish processes from appearing in the list when I split the pipe chain into 3 separate variable assignments:#!/bin/bash
IFS=$'\n'
while : ;do
PSLIST=$(ps -eo pid,start,stat,comm,ppid,args | sort -rk2 | awk '{ print $1 "\n" $2 "\t\t" $3 "\t\t" $4 "\nPPID:"$5,"ARGS:"substr($0, index($0,$6)) }' )
RESULT=$(Xdialog --stdout --ok-label " kill -9 " --item-help --menubox "Processes (sorted by STARTED)" 400x300 0 $PSLIST)
case $? in
0 ) ERR=$(kill -9 $RESULT 2>&1) || { ERR=${ERR##*:} ; Xdialog --msgbox "ERROR:\n$ERR" x ;};;
* ) break ;;
esac
done
Code: Select all
PSLIST=$( ps -eo pid,start,stat,comm,ppid,args)
PSLIST=$( echo -n "$PSLIST" | sort -rk2)
PSLIST=$( echo -n "$PSLIST" | awk '{ print $1 "\n" $2 "\t\t" $3 "\t\t" $4 "\nPPID:"$5,"ARGS:"substr($0, index($0,$6)) }')