From: moonhkt on
On 5¤ë12¤é, ¤W¤È5®É17¤À, Barry Margolin <bar...(a)alum.mit.edu> wrote:
> In article <slrnhuiqjn.4df.hou...(a)penne.houghi>,
>
>
>
>
>
> houghi <hou...(a)houghi.org.invalid> wrote:
> > Geoff Clare wrote:
> > > Barry Margolin wrote:
>
> > >> ppid=`ps -o ppid -p $$ | tail -1`
> > >> gppid=`ps -o ppid -p $ppid | tail -1`
> > >> gpuser=`ps -o user $gppid | tail -1`
>
> > > No need for tail:
>
> > > ppid=`ps -o ppid= -p $$`
> > > gppid=`ps -o ppid= -p $ppid`
> > > gpuser=`ps -o user= -p $gppid`
>
> > After a `su test` where I become the user "test" it indicates root:
> > houghi(a)penne : sh /tmp/tt
> > ++ ps -o ppid= -p 7296
> > + ppid=' 4436'
> > ++ ps -o ppid= -p 4436
> > + gppid=' 4380'
> > ++ ps -o user= -p 4380
> > + gpuser=houghi
> > [~]
> > houghi(a)penne : su test
> > Password:
> > test(a)penne:/home/houghi> sh /tmp/tt
> > ++ ps -o ppid= -p 7339
> > + ppid=' 7311'
> > ++ ps -o ppid= -p 7311
> > + gppid=' 7307'
> > ++ ps -o user= -p 7307
> > + gpuser=root
>
> > Anything I am doing wrong?
>
> The commands have to be run in the shell that su starts up. The first
> command gets the PID of the parent process (su), the second command gets
> the PID of the grandparent (the shell in which you ran su), and the
> third command gets that process's username. By running the commands in
> a shell script, you've added another generation of processes, so you
> have to go back to the great grandparent.
>
> Try: source /tmp/tt
>
> --
> Barry Margolin, bar...(a)alum.mit.edu
> Arlington, MA
> *** PLEASE post questions in newsgroups, not directly to me ***
> *** PLEASE don't copy me on replies, I'll read them in the group ***- ÁôÂóQ¤Þ¥Î¤å¦r -
>
> - Åã¥Ü³Q¤Þ¥Î¤å¦r -

Thank a lot
My version using ps as below
#!/bin/ksh
# Machine AIX
fn=/tmp/abc.txt
ppid=`ps -o ppid -p $$ |tail -1` # remove header
gppid=`ps -o ppid -p $ppid | tail -1`
ps -ef|grep $gppid > $fn
echo ppid=$ppid
echo gppid=$gppid
while read -r i1 i2 i3 i4
do
if [[ "$i2" = "$gppid" ]] ; then
xsu=$i1
fi
done < $fn
echo xsu=$xsu
rm $fn



From: Seebs on
On 2010-05-12, houghi <houghi(a)houghi.org.invalid> wrote:
> Jonathan de Boyne Pollard wrote:
>>> Anything I am doing wrong?

>> Yes. You're putting M. Clare's procedure into a script by r�te without
>> thinking about what the procedure actually does, and thus how and why it
>> works.

> If I knew, I would obviously need not ask. Asking is a part of learning.
> I thought I could do that here. Apparently I was wrong. My bad.

You have misunderstood what's wrong.

> From now on I will only ask question about things I know already what
> the answer is.

You are missing the point.

The problem is not whether or not you know. The problem is whether or not
you even *think*. Think. Come up with theories as to what's going on. If
you don't know what something does, or how it works, don't use it and then
ask why it didn't do what you expected; ask what it does, or how it works.

Slow down and think things through.

Imagine that you were learning English. And you encountered a word you
didn't know. Would you write a paragraph or two using that word repeatedly
in sentences (even though you don't even know whether it's a verb or a noun),
then post the whole work, asking why people don't understand it?

If you don't understand a given hunk of code, don't embed it in something else
and ask why the whole thing is broken; just ask about that hunk of code.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
From: Seebs on
On 2010-05-12, houghi <houghi(a)houghi.org.invalid> wrote:
> Jonathan de Boyne Pollard wrote:
>>> Anything I am doing wrong?

>> Yes. You're putting M. Clare's procedure into a script by r�te without
>> thinking about what the procedure actually does, and thus how and why it
>> works.

> If I knew, I would obviously need not ask. Asking is a part of learning.
> I thought I could do that here. Apparently I was wrong. My bad.

You have misunderstood what's wrong.

> From now on I will only ask question about things I know already what
> the answer is.

You are missing the point.

The problem is not whether or not you know. The problem is whether or not
you even *think*. Think. Come up with theories as to what's going on. If
you don't know what something does, or how it works, don't use it and then
ask why it didn't do what you expected; ask what it does, or how it works.

Slow down and think things through.

Imagine that you were learning English. And you encountered a word you
didn't know. Would you write a paragraph or two using that word repeatedly
in sentences (even though you don't even know whether it's a verb or a noun),
then post the whole work, asking why people don't understand it?

If you don't understand a given hunk of code, don't embed it in something else
and ask why the whole thing is broken; just ask about that hunk of code.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!