PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Named pipes in ksh
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Named pipes in ksh

Réponse
 
LinkBack Outils de la discussion
Vieux 05/12/2006, 00h57   #1
anon
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Named pipes in ksh

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.

  Réponse avec citation
Vieux 05/12/2006, 01h38   #2
bsh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Named pipes in ksh

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

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 14h17.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09489 seconds with 10 queries