reliable replacement for "ps -ef"

On linux redhat 5 I checked the command ps -ef in a loop and found out that it is not reliable.
checked this way:
while [ `ps -ef |grep tnslsnr | grep -v grep | wc -l` -eq 1 ]; do printf . ; done
after about of 2 minutes the loop finished since it didn't find the process.

looking for something more trusted I found the command pgrep
checked this way:
while [ `pgrep tnslsnr 1>/dev/null; echo $?` -ne 1 ]; do printf . ; done
and it is still running in a loop .... ;)
and no need to use awk or grep -v

here are some commands and the behavior of pgrep:
# pgrep smon
# pgrep -f smon
2396
2533
# pgrep -fl smon
2396 ora_smon_orcl
2533 ora_smon_mydb
# pgrep -fl ora_smon_orcl
2396 ora_smon_orcl
# echo $?
0
# pgrep not_exist_process
# echo $?
1

There are some more parameters, check: man pgrep

Comments

Popular posts from this blog

Silent Installation

Data Guard - Changing IP Addresses

Fixing & Registering ORACLE_HOMES in Central Inventory