|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
I'm new to scripting, and I'm attempting to write a script in ksh that
uses named pipes. My pseudo-code is: mkfifo $DATA startReader & sleep 10 # let reader finish initialization startWriter function startReader { request_for_database << !@! 1. perform some initialization on database tables 2. start sucking on named pipe $DATA # blocks here waiting for Writer !@! } function startWriter { <write to named pipe $DATA> } So my goal is: * Reader performs setup on database tables * Reader starts sucking on pipe * After 10 seconds, Writer starts writing to pipe This seems to work fine for the most part - but occasionally the Reader's initialization code fails. In this case, I need to abort the entire process. When the initialization fails: * Reader process immediately dies, before writer starts * Writer blocks waiting for someone to open the pipe for reading At this point I have to kill everyting manually. Is there any code I can put in either the writer or reader that will the situation? What I really want is for the writer to test for the presence of a reader, then abort if no process is listening (b/c iniialization failed) instead of hang. But nothing I've tried does exactly that. If there's a better idea, I'm open to that too. Thanks in advance. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
anon wrote:
> I'm new to scripting, and I'm attempting to write a script in ksh that > uses named pipes. My pseudo-code is: > request_for_database << !@! > # 1. perform some initialization on database tables > # 2. start sucking on named pipe $DATA Databases are kind of a special case, and solutions are usually dependent on which are being used. For Oracle (for instance), see: http://rootshell.be/~yong321/compute...leAndPerl.html Also investigate the perl: BI module. I know it's not ksh(1)and more than you desire to know, but the code is robust and practical. For documents and examples for k/sh(1), see: "Shell Corner: Use Named Pipes in the Shell" http://www.unixreview.com/documents/...1031588957510/ (including the script examples listed after the article.) "qpipe.ksh" http://www.sun.com/bigadmin/scripts/...ipts/qpipe.txt =Brian |
|
![]() |
| Outils de la discussion | |
|
|