how to use wait and notify in ksh on sun system?

how to use wait and notify in ksh on sun system?

Post by Ryan Gaffu » Wed, 23 Apr 2003 23:22:45



I need to run to processes. they will do somethings that require the
use of two files. When they are both complete, I want to delete those
files.

So

job scheduler runs monitor program.
Monitor program executes multiple processes
when processes complete, monitor deletes the files.

can I do this with wait and notify? seems similiar to threads in java.
any sample code? Im really weak in Unix and ksh at the moment. So any
hand holding would be greatly appreciated.

 
 
 

how to use wait and notify in ksh on sun system?

Post by scriptOmati » Thu, 24 Apr 2003 00:54:51



> I need to run to processes. they will do somethings that require the
> use of two files. When they are both complete, I want to delete those
> files.

> So

> job scheduler runs monitor program.
> Monitor program executes multiple processes
> when processes complete, monitor deletes the files.

> can I do this with wait and notify? seems similiar to threads in java.
> any sample code? Im really weak in Unix and ksh at the moment. So any
> hand holding would be greatly appreciated.

There is a program, ksh script, called "working" at
ftp.opensysmon.com/scripts

It might be something like what you are asking for.
It uses SIGUSR1 and SIGUSR2 to have one shell control
the execution of a second (aka child) shell.

--
http://ftp.opensysmon.com is a shell script archive site with an
open source system monitoring and network monitoring software package.
Many platforms are supplied already compiled.

 
 
 

1. wait/notify? [ksh]

Hi !

I'm searching for a way of implementing a kind of condition-variable-like thing
in Korn shell. Basically, I want to start up a series of background processes,
and wait (in the main shell) for them to complete (e.g. by trapping SIGCHLD)

Obviously, the shells that I know of only processes signals between successive
commmands, so what I've (so far) had to do is implement a kind of ugly 'busy
wait' (well, at least a busy sleep)

The implementation looks somewhat like this:
=========
#!/bin/ksh -p
trap 'print -ru2 Got CHLD `date`' CHLD

set -o monitor

(sleep 10; echo "Exiting " `date`) &
(sleep 20; echo "Exiting " `date`) &
(sleep 30; echo "Exiting " `date`) &

# I'd like to get rid of this repeated sleep, it would be nice if something
# like cond_wait(3T) in Solaris existed, (or wait/notify in Java)
myJobs=`jobs`
while [ -n "${myJobs}" ]; do
    sleep 1
    myJobs=`jobs`
done
=========

Does anyone have a better idea of solving this? If so, would you share it with
the rest of us? Thanks in advance,
/Anders

--
------------------------------------------------------------------------------
Anders Olsson          Ericsson Software Technology AB
                       Box 518, 371 23 Karlskrona, Sweden

2. Informix/Oracle/Sybase/DB2

3. fork,exec and wait and wait and wait and wait

4. Is there a sgi-to-something image converter?

5. Ksh: Using 'wait' to parallelize tasks

6. News reruns

7. Need ksh eqivalent of the csh "set notify" command.

8. Creator 3D and mouse problem

9. Wanted: emulation of csh's "set notify" feature in ksh

10. ksh: equivalent to csh's set notify?

11. What's 'side effects' of Ksh built-ins?

12. Telnet wait & wait & wait &....

13. Using a GSM SMS Gateway on WWW to notify incoming mail