public inbox for speakup@linux-speakup.org
 help / color / mirror / Atom feed
* Question about using pid
@  Janina Sajka
   ` John covici
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Janina Sajka @  UTC (permalink / raw)
  To: ma-linux, speakup

I have a command that starts a process. Should that process die whilst
I'm not at my computer, I want a script to restart it.

How do I do this? What doc might I read that would provide examples?

I presume I should launch the process so that it's pid is written to a
file, and then I can just test for the running pid?

But, I don't know how to go forward with this, so would appreciate all
advice and direction.


-- 
	
Janina Sajka
Email: janina@rednote.net		
Phone: (202) 408-8175

Director, Technology Research and Development
American Foundation for the Blind (AFB)
http://www.afb.org

Chair, Accessibility Work Group
Free Standards Group
http://accessibility.freestandards.org


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Question about using pid
   Question about using pid Janina Sajka
@  ` John covici
   ` Luke Davis
   ` Joseph C. Lininger
  2 siblings, 0 replies; 6+ messages in thread
From: John covici @  UTC (permalink / raw)
  To: speakup; +Cc: ma-linux

You might consider using pidof to get the process id of the program
once it is running and I enclose what I use for the speakfreely
monitor -- this might be of help.

#!/bin/bash
secs=15
while true
do
sleep $secs
if [ `pidof sfspeaker | wc -w` != 2 ]
then
#if there are not two sfspeaker processes
aplay -q /usr/src/speak_freely/busy.au
fi
done

on Monday 10/20/2003 Janina Sajka(janina@rednote.net) wrote
 > I have a command that starts a process. Should that process die whilst
 > I'm not at my computer, I want a script to restart it.
 > 
 > How do I do this? What doc might I read that would provide examples?
 > 
 > I presume I should launch the process so that it's pid is written to a
 > file, and then I can just test for the running pid?
 > 
 > But, I don't know how to go forward with this, so would appreciate all
 > advice and direction.
 > 
 > 
 > -- 
 > 	
 > Janina Sajka
 > Email: janina@rednote.net		
 > Phone: (202) 408-8175
 > 
 > Director, Technology Research and Development
 > American Foundation for the Blind (AFB)
 > http://www.afb.org
 > 
 > Chair, Accessibility Work Group
 > Free Standards Group
 > http://accessibility.freestandards.org
 > 
 > _______________________________________________
 > Speakup mailing list
 > Speakup@braille.uwo.ca
 > http://speech.braille.uwo.ca/mailman/listinfo/speakup

-- 
         John Covici
         covici@ccs.covici.com


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about using pid
   Question about using pid Janina Sajka
   ` John covici
@  ` Luke Davis
     ` Joseph C. Lininger
   ` Joseph C. Lininger
  2 siblings, 1 reply; 6+ messages in thread
From: Luke Davis @  UTC (permalink / raw)
  To: speakup

The start-stop-daemon program, might help you with this.

Any kind of do while, while, or similar loop, can do this, as the PID
doesn't have to matter.  If you keep the process in the foreground, the
shell's next command can not run until the command exits.  So, if you put
it in a while loop, the shell's next command will be to restart the loop,
thus rerunning the program, and achieving what you want.

If you want to test for fail conditions, put an if test for $? after the
command, with a break command to be executed if the program returns
anything other than zero.

Luke




On Mon, 20 Oct 2003, Janina Sajka wrote:

> I have a command that starts a process. Should that process die whilst
> I'm not at my computer, I want a script to restart it.
>
> How do I do this? What doc might I read that would provide examples?
>
> I presume I should launch the process so that it's pid is written to a
> file, and then I can just test for the running pid?
>
> But, I don't know how to go forward with this, so would appreciate all
> advice and direction.
>
>
>

-- 
Want a free month of internet access on a great ISP?  Go here:
http://www.tacticus.com/net/


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about using pid
   Question about using pid Janina Sajka
   ` John covici
   ` Luke Davis
@  ` Joseph C. Lininger
  2 siblings, 0 replies; 6+ messages in thread
From: Joseph C. Lininger @  UTC (permalink / raw)
  To: speakup

I'd check out the daemontools package.
http://cr.yp.to/ddaemontools.html

This tool has features to do what you want, plus a hole host of other stuff.
An alternative would be to use a script to monitor for changes in process
status, but this would be clumsy at best.
--
Joseph C. Lininger
jbahm@pcdesk.net
----- Original Message ----- 
From: "Janina Sajka" <janina@rednote.net>
To: <ma-linux@tux.org>; <speakup@braille.uwo.ca>
Sent: Monday, October 20, 2003 11:13 AM
Subject: Question about using pid


> I have a command that starts a process. Should that process die whilst
> I'm not at my computer, I want a script to restart it.
>
> How do I do this? What doc might I read that would provide examples?
>
> I presume I should launch the process so that it's pid is written to a
> file, and then I can just test for the running pid?
>
> But, I don't know how to go forward with this, so would appreciate all
> advice and direction.
>
>
> -- 
>
> Janina Sajka
> Email: janina@rednote.net
> Phone: (202) 408-8175
>
> Director, Technology Research and Development
> American Foundation for the Blind (AFB)
> http://www.afb.org
>
> Chair, Accessibility Work Group
> Free Standards Group
> http://accessibility.freestandards.org
>
> _______________________________________________
> Speakup mailing list
> Speakup@braille.uwo.ca
> http://speech.braille.uwo.ca/mailman/listinfo/speakup
>



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about using pid
   ` Luke Davis
@    ` Joseph C. Lininger
       ` Luke Davis
  0 siblings, 1 reply; 6+ messages in thread
From: Joseph C. Lininger @  UTC (permalink / raw)
  To: speakup

This works fine, but there is one problem. If something should happen to the
script that is running your process, the process may die two (this depends
on the system) and the process will definitely siece to be restarted
automatically. If it is absolutely critical that the process run, then you
need a solution that is run by init, and so will be restarted if it dies. An
alternative would be to simply put the process you want to run in to init,
but I recommend against this for two reasons. First, this pokes a security
hole in your system depending on what you are running. the other problem is
that processes can not be easily shut down while the system is running if
they are in the inittab file.
--
Joseph C. Lininger
jbahm@pcdesk.net
----- Original Message ----- 
From: "Luke Davis" <ldavis@shellworld.net>
To: <speakup@braille.uwo.ca>
Sent: Monday, October 20, 2003 3:16 PM
Subject: Re: Question about using pid


> The start-stop-daemon program, might help you with this.
>
> Any kind of do while, while, or similar loop, can do this, as the PID
> doesn't have to matter.  If you keep the process in the foreground, the
> shell's next command can not run until the command exits.  So, if you put
> it in a while loop, the shell's next command will be to restart the loop,
> thus rerunning the program, and achieving what you want.
>
> If you want to test for fail conditions, put an if test for $? after the
> command, with a break command to be executed if the program returns
> anything other than zero.
>
> Luke
>
>
>
>
> On Mon, 20 Oct 2003, Janina Sajka wrote:
>
> > I have a command that starts a process. Should that process die whilst
> > I'm not at my computer, I want a script to restart it.
> >
> > How do I do this? What doc might I read that would provide examples?
> >
> > I presume I should launch the process so that it's pid is written to a
> > file, and then I can just test for the running pid?
> >
> > But, I don't know how to go forward with this, so would appreciate all
> > advice and direction.
> >
> >
> >
>
> -- 
> Want a free month of internet access on a great ISP?  Go here:
> http://www.tacticus.com/net/
>
> _______________________________________________
> Speakup mailing list
> Speakup@braille.uwo.ca
> http://speech.braille.uwo.ca/mailman/listinfo/speakup
>



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about using pid
     ` Joseph C. Lininger
@      ` Luke Davis
  0 siblings, 0 replies; 6+ messages in thread
From: Luke Davis @  UTC (permalink / raw)
  To: speakup

Well, not necesarily...

Put the word "stop" or "run", as the case may be, in the control file.

Put this in inittab:

f1:2345:respawn:/usr/local/bin/myscript

Then, in myscript:

#!/bin/bash
# Set the control file's path
file=/etc/myscriptrc
# Set the default instruction
instruction="start"
# See if the control file exists
if [ -a $file ]; then
	# Read in the file
	source $file;
else
	# Otherwise, create it
	echo 'instruction=' $instruction ';' > $file;
fi
# If the instruction is to stop: sleep and exit
if [ "$instruction" == "stop" ]; then
	sleep 120;
	exit 0;
else
	# Run the command that all of this is about
	/usr/local/bin/myrealcommand -option1 --option2
fi
# Get out
exit 0;





On Mon, 20 Oct 2003, Joseph C. Lininger wrote:

> This works fine, but there is one problem. If something should happen to the
> script that is running your process, the process may die two (this depends
> on the system) and the process will definitely siece to be restarted
> automatically. If it is absolutely critical that the process run, then you
> need a solution that is run by init, and so will be restarted if it dies. An
> alternative would be to simply put the process you want to run in to init,
> but I recommend against this for two reasons. First, this pokes a security
> hole in your system depending on what you are running. the other problem is
> that processes can not be easily shut down while the system is running if
> they are in the inittab file.
> --
> Joseph C. Lininger
> jbahm@pcdesk.net
> ----- Original Message -----
> From: "Luke Davis" <ldavis@shellworld.net>
> To: <speakup@braille.uwo.ca>
> Sent: Monday, October 20, 2003 3:16 PM
> Subject: Re: Question about using pid
>
>
> > The start-stop-daemon program, might help you with this.
> >
> > Any kind of do while, while, or similar loop, can do this, as the PID
> > doesn't have to matter.  If you keep the process in the foreground, the
> > shell's next command can not run until the command exits.  So, if you put
> > it in a while loop, the shell's next command will be to restart the loop,
> > thus rerunning the program, and achieving what you want.
> >
> > If you want to test for fail conditions, put an if test for $? after the
> > command, with a break command to be executed if the program returns
> > anything other than zero.
> >
> > Luke
> >
> >
> >
> >
> > On Mon, 20 Oct 2003, Janina Sajka wrote:
> >
> > > I have a command that starts a process. Should that process die whilst
> > > I'm not at my computer, I want a script to restart it.
> > >
> > > How do I do this? What doc might I read that would provide examples?
> > >
> > > I presume I should launch the process so that it's pid is written to a
> > > file, and then I can just test for the running pid?
> > >
> > > But, I don't know how to go forward with this, so would appreciate all
> > > advice and direction.
> > >
> > >
> > >
> >
> > --
> > Want a free month of internet access on a great ISP?  Go here:
> > http://www.tacticus.com/net/
> >
> > _______________________________________________
> > Speakup mailing list
> > Speakup@braille.uwo.ca
> > http://speech.braille.uwo.ca/mailman/listinfo/speakup
> >
>
>
> _______________________________________________
> Speakup mailing list
> Speakup@braille.uwo.ca
> http://speech.braille.uwo.ca/mailman/listinfo/speakup
>

-- 
Want a free month of internet access on a great ISP?  Go here:
http://www.tacticus.com/net/


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~ UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
 Question about using pid Janina Sajka
 ` John covici
 ` Luke Davis
   ` Joseph C. Lininger
     ` Luke Davis
 ` Joseph C. Lininger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).