LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-30-2012, 01:31 PM   #1
esolve
LQ Newbie
 
Registered: Oct 2012
Posts: 18

Rep: Reputation: Disabled
make shell script wait and send signal to recover it


when running a shell script
I want to make it wait for a signal somewhere inside the script,
like

Code:
function pause(){
   read -p "$*"
}
echo "start"
pause
echo "stop"
and then send a signal(when some conditions are satisfied) to make the script continue

is it possible or not?
thanks!
 
Old 10-30-2012, 03:07 PM   #2
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
I can't explain it b/c I haven't used it.
But here's some notes that may help.

Code:
...
#launching your program:
myprog&
#getting its id
id=$!
#killing it whenever you want
kill $id
...
#sleep for xx and restart script
do_stuff &
pid=$?
sleep xx
kill $pid
wait $pid
NOTE: These are 2 separate snippets.

David the H: should be along any minute...
 
Old 11-01-2012, 12:36 PM   #3
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
You mean POSIX signals? You can start one script in the background:
Code:
#!/bin/sh
echo "running PID=$$"
echo "start"
do_some_stuff_before
kill -stop $$
do_some_stuff_after
echo "stop"
Then it will stop and you can wake it up again by sending this process a signal to continue:
Code:
$ kill -cont 1234
by replacing the 1234 with the PID the first script output.
 
Old 11-02-2012, 10:13 PM   #4
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
Blog Entries: 2

Rep: Reputation: 244Reputation: 244Reputation: 244
select() on file input is another way to get a program to stop executing until a condition is met. For anything at all complicated I recommend Perl over shell.
 
Old 11-04-2012, 12:58 AM   #5
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
Put the operative portion in a
Quote:
while <condition_is_not-satisfied>
do
...
...
done
loop
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Script: Getting signal handlers to work when running an application by script pkjss Programming 4 09-14-2011 04:23 AM
Shell script: How to wait on two processes at the same time dbrazeau Programming 16 03-18-2010 12:33 PM
How to make shell script wait for a particular key pressed in order to proceed? Caed Lucin Linux - General 5 01-31-2010 06:08 PM
How to make shell script wait for key press to proceed... ddenton Linux - General 13 12-02-2008 04:25 AM
Wait for one of two processes to complete in a shell script nonoitall Programming 11 06-10-2008 04:10 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration