ps -ef | grep pmon
PMON (process monitor) process checks all other background processes. Then you must check database's alert_<SID>.log for further investigation.
check in different operating systems and gets os user.
SCRIPT=${0##*/}
sid="ORCL"
PMON_PROCESS="ora_pmon_${sid}"
echo "Definition Oracle Pmon_Prozess: ${PMON_PROCESS}"
pid=$( UNIX95=TRUE ps -eo pid,args | awk '( ($NF == "'${PMON_PROCESS}'" ) && ($1 != mypid) ){ print $1 }' mypid=$$ )
if [ "X${pid}" = "X" ]; then
echo "${SCRIPT}: Database "${v_sid}" (pid=${pid}) not started."
exit 1
else
ORA_RUN_RELEASE=$( UNIX95=TRUE ps -eo pid,user,args | awk '( ($NF == "'${PMON_PROCESS}'" ) && ($1 != mypid) ){ print $2 }' mypid=$$ )
fi
Or Python version (inspired by Tanel Poder's findhomes.sh)
#!/usr/bin/python3
import os
import glob
Emulate trick form tanelpoder
https://tanelpoder.com/2011/02/28/finding-oracle-homes-with/
printf "%6s %-20s %-80s\n" "PID" "NAME" "ORACLE_HOME"
pgrep -lf pmon |
while read pid pname y ; do
printf "%6s %-20s %-80s\n" $pid $pname ls -l /proc/$pid/exe | awk -F'>' '{ print $2 }' | sed 's/bin\/oracle$//' | sort | uniq
done
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
for cmd_line_file in glob.glob('/proc/[0-9]*/cmdline'):
try:
with open(cmd_line_file) as x:
cmd_line = x.read().rstrip("\x00")
if not cmd_line.startswith('ora_pmon_'):
continue
, _, SID = cmd_line.split('')
#
piddir = os.path.dirname(cmd_line_file)
exefile = os.path.join(piddir, 'exe')
inode = os.stat(exefile)
#
if not os.path.islink(exefile):
continue
oraclefile = os.readlink(exefile)
ORACLE_HOME = os.path.dirname(oraclefile)
ORACLE_HOME = os.path.dirname(ORACLE_HOME)
print("{sid:20s} {home}".format(sid=SID, home=ORACLE_HOME))
except FileNotFoundError:
#print("Missing file ignored: {}".format(cmd_line_file)) # process exited quickly
pass