I had a question about how to quickly identify which Oracle process runs out of which ORACLE_HOME on Linux.
I have uploaded a little script for that – it’s basically looking up all PMON process IDs and then using /proc/PID/exe link to find out where is the oracle binary of a running process located.
You may have to run this as root (as on some Linux versions I get “ls: cannot read symbolic link: Permission denied” error even when running this command as the owner of all Oracle homes (it seems to happen when your users UID and primary GID are different than thet setuid/setgid bits on the oracle binary):
oracle@linux03:~$ sudo ./findhomes.sh PID NAME ORACLE_HOME 4421 asm_pmon_+ASM /u01/app/oracle/product/11.2.0/db_1/ 4545 ora_pmon_demo112 /u01/app/oracle/product/11.2.0/dbhome_1/ 4547 ora_pmon_test112 /u01/app/oracle/product/11.2.0/dbhome_1/
You can use a similar approach on other Unixes too where the executable location or current working directory (CWD) is externalized in the /proc filesystem – or just use pmap to get this info instead.






Thanks, working under oracle user on RHEL4.
[oracle@lv-test ~]$ ./findhomes.sh
PID NAME ORACLE_HOME
7112 ora_pmon_SET2 /opt/oracle/920/
7294 ora_pmon_CL2 /opt/oracle/112/product/11.2.0/dbhome_1/
All ORACLE homes under one user.
#!/bin/bash
printf “%6s %-20s %-80s\n” “PID” “NAME” “ORACLE_HOME”
pgrep -lf _pmon_ |
while read pid pname y ; do
if [ `uname` = "SunOS" ]; then
printf “%6s %-20s %-70s\n” $pid $pname `pfiles $pid | grep dbs | sed ‘s/dbs.*//’ | uniq`
else
printf “%6s %-20s %-80s\n” $pid $pname `ls -l /proc/$pid/exe | awk -F’>’ ‘{ print $2 }’ | sed ‘s/bin\/oracle$//’ | sort | uniq`
fi
done
I have added Solaris support and a simple if-then-else structure. This should work on both Linux and Solaris 10. Unfortunately I couldn’t tested it on Linux.
@Gokhan Atil
Cool, thanks. I’ve used pmap on Solaris so far, but pfiles can do this too…
People who are copying & pasting Gokhan’s script – you probably need to replace the “fancy” quotes which WordPress put in place with regular single quotes…
Alternatively, one could use the script dbhome that Oracle provides:
pgrep -lf ora_smon | while read p a; do printf '%s %-15s => %s\n' "$p" "$a" \ "$( dbhome "${a#ora_smon_}" )" doneAt last… after you took a month off from blogging! ;-)
@Simon
Yeah, it has been very hard to find time for blogging lately – but at least I am writing something – my part of the Expert Oracle Exadata book :-)
@Dimitre Radoulov
Dimitre,
If I recall correctly then the dbhome script just greps the instance name from /etc/oratab – which may not be correct in some cases or not used at all if the DBAs use some other standard for starting/stopping instances (clusterware etc)
@Tanel Poder
Hi Tanel,
yes, that code won’t work for installations that don’t use oratab (i.e. non-standard installations).
@Tanel Poder
Excellent. Looking forward to that!
pfiles? man pwdx
@Laurent Schneider
Yep that would also work on Solaris. just like /proc/pid/cwd on Linux… Might even be faster than running pmaps or pfiles commands…