Operating System - HP-UX
1748261 Members
3730 Online
108760 Solutions
New Discussion юеВ

Re: retrieve absolute path from pid

 
SOLVED
Go to solution
Senthilprakash_1
New Member

retrieve absolute path from pid

hi,

I have the pid of the process. Using this pid i should retrieve the absolute path name of the executable. I tried pstat_getproc(), but it gives only the basename of the executable. I need the full path. Is there any system call available in HP-UX to do that or can i do this using scripting?

Thanks,
Prakash.
15 REPLIES 15
Robert-Jan Goossens
Honored Contributor

Re: retrieve absolute path from pid

Hi Prakash,

# UNIX95= ps -e -o ruser,pid,vsz,args

Regards,
Robert-Jan
Franky_1
Respected Contributor

Re: retrieve absolute path from pid

Hi,

you can user the "UNIX95" option

eg

UNIX95= ps -eo time,vsz,pid,args

(see "columns" from man ps for more options)
and be aware of the " " before ps
This should give you what you want

Regards

Franky
Don't worry be happy
Bharat Katkar
Honored Contributor

Re: retrieve absolute path from pid

HI Prakash,
How about this one.

# PIDNO=xxxx
# ps -ef | grep $PIDNO | grep -v grep | awk '{ print $9 }'

Hope that helps.
Regards,
You need to know a lot to actually know how little you know
Senthilprakash_1
New Member

Re: retrieve absolute path from pid

hi,

I invoke a executable ./a.out in /tmp/one.
Now i am in some different directory and try using the script provided i still get as
./a.out and not as /tmp/one/a.out.

Prakash
Robert-Jan Goossens
Honored Contributor

Re: retrieve absolute path from pid

you wont, the process is being started as ./a.out ( no full path )

if you start is as # /tmp/one/a.out (without the .)the full path wil be visible in the ps list.
Muthukumar_5
Honored Contributor

Re: retrieve absolute path from pid

I hope you are expecting full path and execution of a process there. We can do in linux using /proc filesystem. Every process ID contains exe part which gives link to exact execution path there.

We can not get it using ps command there. We can get basename of execution, if we execute them as only that command. We can full path name when we does with full path name.

You can go to glance tool, to know more about a process there. I am not sure which will give or not.

HTH.
Easy to suggest when don't know about the problem!
Petr Simik_1
Valued Contributor

Re: retrieve absolute path from pid

You cann't get PATH from ps everytime.

PATH output from ps is limited to 80 characters. If the PATH is longer you don't get it.

I am curious if anybody know how to get full PATH.
Bill Hassell
Honored Contributor

Re: retrieve absolute path from pid

The full path is not stored in the process table unless the process is started with a full path (ie, starts with /). You can see the full path and the parameters (very common request for Java stuff) by using -x as in:

ps -efx

NOTE: -x is *only* available for patched versions of ps (11.00 and 11i only).


Bill Hassell, sysadmin
Senthilprakash_1
New Member

Re: retrieve absolute path from pid

If I wont be able to retrieve the full pathname using "ps" then is there any system call and work around which will get me abolsute path using pid.

Thanks,
Prakash.