Using PS to find a process and then restarting if not found (HELP)

Using PS to find a process and then restarting if not found (HELP)

Post by Michael Geor » Sat, 10 Sep 1994 23:16:24



Background Information                        
I am running SCO Unix and have an application which requires a port
speed to 4800 baud. In SCO Unix the default serial port speed is 9600
and can not be modified. So, I use the equivalent of a "hold open"
script which keeps the port speed set to 4800 baud. Sometimes this
process dies off, don't know why or how and I would like to restart it.

Before I restart it I would like to check and see if it is already
running, if it isn't running then restart. Can someone advise me in the
simplest way to test? I am not a real strong script programmer but I've
got a good book and have constructed many complex scripts.

Thanks in advance,
Michael George III              "Trust me, I know what I'm doing ..."
Systems Programmer
Medical Knowledge Systems
(313) 832-1500

 
 
 

Using PS to find a process and then restarting if not found (HELP)

Post by Craig Ludingt » Sun, 18 Sep 1994 11:25:48


 [deletia]
: script which keeps the port speed set to 4800 baud. Sometimes this
: process dies off, don't know why or how and I would like to restart it.

: Before I restart it I would like to check and see if it is already
: running, if it isn't running then restart. Can someone advise me in the
: simplest way to test? I am not a real strong script programmer but I've
: got a good book and have constructed many complex scripts.

In sh (ksh, bash):

------------- cut here -------------
#!/bin/sh
# daemon process whose pid you'd like to know later
PIDFILE="daemon.pid"
trap "rm $PIDFILE" 1 2 3 15

echo $$ > $PIDFILE

# do the rest of your processing here

------------- cut here -------------
#!/bin/sh
# other process that needs to know if the daemon process is running
PIDFILE="daemon.pid"
ps -list_all_processes_option_for_your_ps |
grep -quiet_option_for_your_grep `cat $PIDFILE`
if test $? -eq 0; then
   ... the daemon process is running ...
else
   ... the daemon process is dead, Jim ...
fi

------------- cut here -------------
The daemon writes its pid to a file you know about.  The trap
removes the file when the daemon gets killed.
The ps option may be "aux" or "ef".  The grep option may be "s"
or "q".

 
 
 

1. Find exact creation time of a process; not kill a wrong process

(1)
Is there a portable way in Shell, Perl, other tools to find
the exact number of seconds since epoch of a process?

timestamp on /proc/<pid> disqualifies as it is not portable,
Linux /proc/<pid> is always current time.

"current time - elapsed time from ps" disqualifies as
current time and elapsed time from ps are taken at different
times, it may be off by a few seconds.

(2)
How can I kill a process without worrying killing a wrong process?
For example,

some_process & pid=$!
kill $pid

The $pid may be a recycled new process.

I am building an application used on space shuttle, and need
100% reliability. Please help.

Thanks.
--

2. OpenGL for Riva TNT?

3. Linux program can't find ifs lib file -- help

4. Installing Mandrake 7.1 with Windows ME

5. How to find all hidden file on Unix, and how can i find hidden process?

6. KDM\XDM and console log problem

7. Need to find vi command to remove ^H from command man find > find.txt

8. Need career advice--Where to go after CNA?

9. script to find altered files (actually only using find)

10. find without the "find: cannot read dir /usr/lost+found: Permission denied"

11. ** Using "find" to find files created today? ***

12. using find and egrep and then print file name where match was found

13. RH7: network can't restart : ifup not found ???