-   Linux - Newbie (
-   -   How to find owner of a process (

vkarna 10-19-2007 04:59 AM

How to find owner of a process

I have 2 questions and both are in Perl context.

1. Suppose I know just the process id of a process, I want to know how can I get the process owner.

2. I know if I run a script I can know the process id by print $$ and get its parent using getppid function. But If I want to know the grandparent and its parent and so on i.e the whole process tree backwards, how can I achieve that ?

Can someone help me out here.

Thanks in advance

lugoteehalt 10-19-2007 06:50 AM

Would have thought 'top' would do the first job. Type top and then look opposite the known pid. ps 'll probably have a way of doing it too, man pid.

From memory 'think there is something that does this, but have forgotten the name .... it's called pstree.

vkarna 10-19-2007 09:58 AM

Thanks for your answers.

I believe I was not very clear with my question. Actually I am looking for any builtin functions within perl or linux or any cpan module which will give me this information.

You are right that I can run ps command and then parse it using awk to get the process owner and parent process id and can continue it like that way to get the whole tree backwards but I found this process a bit time consuming.

Also pstree will give the process tree out of that process id, here I want the tree backwards not forward.

Any information on a perl builtin or a capn module which can give me the process owner name given the process id would be very useful.


vkarna 10-19-2007 10:01 AM

However you are right with ps command. So if I do not get any other information, I will have no other alternatives but to use ps to get this information.


All times are GMT -5. The time now is 08:58 AM.