- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Need to monitor the existance of a process
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-27-2006 02:37 AM
тАО11-27-2006 02:37 AM
I'm an idiot asking this, i know, but i need to monitor a process of it's existance.
A monitor script must run in a loop until the monitored process has finished. then it has to exit.
while ....
ps -ef | grep PROCESS
...
Please fill in the blanks.
I have a bit of a programmers block at the moment.
Kl@@s
Solved! Go to Solution.
- Tags:
- PS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-27-2006 02:47 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-27-2006 02:50 AM
тАО11-27-2006 02:50 AM
Re: Need to monitor the existance of a process
many solutions possible.
#!/usr/bin/sh
a=1
process="fred"
while [ $a -eq 1 ]
do
a=`ps -ef | grep $process | grep -v grep | wc -l`
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-27-2006 03:05 AM
тАО11-27-2006 03:05 AM
Re: Need to monitor the existance of a process
Whatever you do, don't rely on a 'grep' of the process table to select processes by name. The UNIX95 (XPG4) option with 'ps' allows you to select a process by its basename, thereby eliminating false matches.
This would work. Change the value of NAME to match your process.
# cat ./monitor
#!/usr/bin/sh
NAME=sleep
PID=`UNIX95= ps -C ${NAME} -o pid=`
while [ ! -z "${PID}" ]
do
PID=`UNIX95= ps -C ${NAME} -o pid=`
if [ -z "${PID}" ]; then
break
else
echo "alive!"
sleep 5
fi
done
echo "exiting..."
Regards!
...JRF...
- Tags:
- UNIX95
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-27-2006 03:40 AM
тАО11-27-2006 03:40 AM
Re: Need to monitor the existance of a process
Something like this:
#!/usr/bin/sh
typeset -i PROC_PID=0
typeset -i KILL_STAT=0
typeset MY_PROC=/xxx/yyy/zzz.exe # the process to start and monitor
${MY_PROC} & # start in background
PROC_PID=${!} # capture its PID
while [[ ${KILL_STAT} -eq 0 ]]
do
kill -0 ${PROC_PID} 2>/dev/null
KILL_STAT=${?}
if [[ ${KILL_STAT} -eq 0 ]]
then
sleep 10
else
echo "Process ${PROC_PID} has terminated."
fi
done
kill -0 PID returns a zero exit status if PID is a valid process ID and non-zero if not.
- Tags:
- kill
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-27-2006 03:47 AM
тАО11-27-2006 03:47 AM
Re: Need to monitor the existance of a process
I need to start a command to list the batchpocesses of a program and based on that output i have to check if a specific batchprocess is still running or finished.
Sorry for the misslead with the line ps -ef but i had to think of a simple exsample to point my problem.
My real problem is, before the backup of a program i have to start a triggerprogram for the batchprocesses within the application to stop (not at or cron).
But this program is also a batch program so i have to wait till this program kicks-in and does it's work and after the last program exits the batch the backup script must continue with the actual backup.
So i have to wait for a program with a delay to shut down other programs with a delay, and how big that delay is i do'nt now and i get no reply if the programs are finished or not.
The only thing i have is a list of currently running batch processes.
Do i have to be original on this or not . . .
Well, Jeff's solution helped me so far, tomorrow i'll know more.
Thanks for the replies.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-27-2006 03:08 PM
тАО11-27-2006 03:08 PM
Re: Need to monitor the existance of a process
I would strongly recommend that the other process(es) be rewritten to report an exit status, perhaps through a simple text file. And the monitoring script needs to perform a sanity check in case no completion file is created after several hours.
If you write code with the idea that everything is going to fail, you won't be disappointed.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-27-2006 03:56 PM
тАО11-27-2006 03:56 PM
Re: Need to monitor the existance of a process
as mentioned by Bill above, you should ensure that the programs returns an exit status and all you have to do is write a notification programs that informs you. Can be a mail notification or just modification of a status file or table column in a database.
e.g.
SCRIPT_STATUS=`
if [ "$SCRIPT_STATUS" != "SUCCESSFUL" ]
then
echo "Error running script <script name>"|mailx -s "error notification" youraddress@domain.mu
fi
hope this helps too!
kind regards
yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-27-2006 09:37 PM
тАО11-27-2006 09:37 PM
Re: Need to monitor the existance of a process
Outside the applications you can not tell if or how the batchjob ended.
There is only a fuction to view a list of current processes of the application.
Probably there would be a way to digg in the oracle database underneath to see what batchjobs are running and if they are finished but i'm no oracle guru.
There solution was to stop the batchjobs with the trigger program from cron for lets say 10 minutes in advance of the backup and if this was not sufficient i had to increase that time.
That option is mot acceptable for me because the batchprogram supplies information to otherprograms like SAP and that would mean that these SAP applications can also not be used during that time.
Well last night all seemd to go well so i'll see what happns tonight.
Klaas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-28-2006 07:54 PM
тАО11-28-2006 07:54 PM
Re: Need to monitor the existance of a process
could you please update the thread with the result of your overnight run.
Another idea I had was to use the wait command to wait for the completion of a specific process before the next process starts.