The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Reading from blocking fifo pipe in shell script victorin Shell Programming and Scripting 4 05-08-2007 12:39 PM
Blocking a Single IP Phobos UNIX for Dummies Questions & Answers 4 04-28-2005 12:09 AM
blocking DHCP byblyk IP Networking 2 03-16-2005 12:06 AM
School Blocking Satine IP Networking 1 02-07-2005 05:07 PM
blocking domains tamemi UNIX for Dummies Questions & Answers 1 04-16-2003 08:13 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-09-2009
cdlaforc cdlaforc is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 4
Non-blocking pipe

Hello,
Would this be an acceptable way of creating a non-blocking pipe.
Basically I want to create kind of a server client arch.
This code would be in the server, and I don't want to have to wait for
clients to read before moving on to the next client. One problem I
can see is if a client leaves/dies and never reads from the pipe(but I
could have some trap/cleanup stuff in the clients for that).

# assigning fd 3 to the pipe
echo "exec 3>myfifo && echo 'a' >&3 && echo 'b' >&3 && echo 'c' >&3 &&
exec 3>&-" | at now



Chris.

Last edited by Neo; 02-09-2009 at 05:25 PM.. Reason: removed self promoting link of new member
  #2 (permalink)  
Old 02-09-2009
Corona688 Corona688 is online now
Registered User
  
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 1,952
A UNIX domain socket is essentially a FIFO with the extra properties you want -- the ability for multiple clients to connect to one server. See this link for details.
  #3 (permalink)  
Old 02-09-2009
cdlaforc cdlaforc is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 4
Thanks for the info. I would like to keep this in shell script(bash). It's kind of a learning project trying to learn all I can about shell scripting for bash. So I'm trying to build a little shell game.
Thanks,


Chris.
  #4 (permalink)  
Old 02-10-2009
Corona688 Corona688 is online now
Registered User
  
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 1,952
The && will cause the shell to wait before running the command after it, and should any of them fail, none of the ones after it will run. && is a conditional, it's not a background statement. Also, is there any particular reason that string of commands is all in one line? And what is 'echo exec' for, did you mean for that to be without the echo?

I don't think there's any point trying to open it as a FD in the shell if you're trying to save time, since the shell will wait for the reader to open the pipe anyway. Once it does, all three processes will get the same pipe, which I doubt is what you want. at which point all three processes will get copies of the same pipe, not queue up.

This sort of code, on the other hand, will wait for the pipe, launch a process, then immediately wait on the pipe again without waiting for the launched process to finish:
Code:
echo a > fifo &
echo b > fifo &
echo c > fifo &
  #5 (permalink)  
Old 02-10-2009
cdlaforc cdlaforc is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 4
Corona688,
Thanks for the info.

Quote:
The && will cause the shell to wait before running the command after it, and should any of them fail, none of the ones after it will run. && is a conditional, it's not a background statement. Also, is there any particular reason that string of commands is all in one line? And what is 'echo exec' for, did you mean for that to be without the echo?
I think my line wrapped here when I pasted it which made it a little confusing. I was echoing out that string of commands and piping them into at. I thought that because they were being piped into at that I needed to keep them in the same statement because otherwise the second echo command wouldn't know about the fd assigned to the pipe, but I pretty sure your right that I don't need a fd descriptor. Also, with how I want to do develop this I don't really need to send multiple lines to the fifo without reopening the reader.

Thanks again,


Chris.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:18 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0