On 3/26/09 5:47 PM, Carey Tyler Schug wrote:
My 2 cents:
I am not an expert.
I easily found a way to find a way to get a list of all processes in the
parent tree of my existing task in Solaris, but even asking for help on
the local Linux user group, could not find a way in Linux, short of
writing a program with a loop containing tests.. This was several years
ago, so if it has changed, please ignore this, except that it may
indicate Solaris is "ahead" of Linux. At the time I was trying to move
my tools to Linux, there were other ways I felt Linux had glitz but not
nitty gritty ease of use, but that my have only been my ignorance. The
closest Linux equivalent to pstree is pretty with a full color display,
but can't be limited to one branch.
Here Solaris code:
mypid=`ps -opid`
mypid=`echo $mypid|cut -d" " -f2`
mycons=`/usr/proc/bin/ptree $mypid|grep console.|grep -v grep|wc -l`
I see a gauntlet...
pstree -hAp | egrep "($$)" | egrep -q console \
&& <do what you want to do if console is already running in your ancestry> \
|| <do what you want to do if console isn't already running>
(BTW avoid "grep -v grep" -- use "grep [c]onsole" in the prior grep. I'd
also avoid the "wc -l" thing just to find out if something matches --
that's what grep is for, especially with the -q flag.)
I've been using pstree (usually pstree -hlupaG) in Linux for a long
time, so this isn't a "new" thing -- I think your "local Linux user
group" was a bit inexperienced. And the loop they complained about?
$ x=$$; until [ $x -eq 0 ]; do ps -ocmd= -p $x; x=$(ps -oppid= -p $x); done
-bash
sshd: la...@pts/0
sshd: larry [priv]
/usr/sbin/sshd
init [3]
Feh.
*Larry Ploetz
Systems Administrator
Carnegie Institution of Washington
Department of Plant Biology
The Arabidopsis Information Resource
650 325 1521 x 296 [email protected] *
----------------------------------------------------------------------
For LINUX-390 subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390