Non-blocking pipe


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Non-blocking pipe
# 1  
Old 02-09-2009
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  
Old 02-09-2009
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  
Old 02-09-2009
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  
Old 02-10-2009
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  
Old 02-10-2009
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Which are blocking and non-blocking api's in sockets in C ?

among the below socket programming api's, please let me know which are blocking and non-blocking. socket accept bind listen write read close (2 Replies)
Discussion started by: VSSajjan
2 Replies

2. Shell Programming and Scripting

How to ignore Pipe in Pipe delimited file?

Hi guys, I need to know how i can ignore Pipe '|' if Pipe is coming as a column in Pipe delimited file for eg: file 1: xx|yy|"xyz|zzz"|zzz|12... using below awk command awk 'BEGIN {FS=OFS="|" } print $3 i would get xyz But i want as : xyz|zzz to consider as whole column... (13 Replies)
Discussion started by: rohit_shinez
13 Replies

3. IP Networking

ping blocking

Hi I am starting to practice nmap for my own education. Now I created two host in virtual box. Bot are scientific linux, one in installed as web server and the other as developing station. I tried to run nmap on so I did nmap on their IP address, I got an answer that ip is down or that... (8 Replies)
Discussion started by: programAngel
8 Replies

4. Shell Programming and Scripting

Replace pipe with Broken Pipe

Hi All , Is there any way to replace the pipe ( | ) with the broken pipe (0xA6) in unix (1 Reply)
Discussion started by: saj
1 Replies

5. UNIX for Dummies Questions & Answers

Blocking signals

I know how to add signal to a set. But what if I want to add 2 or 3 signals to the set. I know I can use sigaddset (&set,SIGBUS)....but what if I want to add SIGBUS and SIGALRM at once. Do i have to do it like this.. sigaddset (&set,SIGBUS); sigaddset (&set,SIGALRM); Is there another way to... (0 Replies)
Discussion started by: joker40
0 Replies

6. UNIX for Advanced & Expert Users

ps blocking

Hi Folks I have been debugging a script that is called every thirty seconds. Basically it is doing a ps, well two actually, one to file (read by the getline below) and the other into a pipe. The one into the pipe is: - V_SYSVPS=/usr/sysv/bin/ps $V_SYSVPS -p$PIDLIST -o$PSARGS... (0 Replies)
Discussion started by: steadyonabix
0 Replies

7. Shell Programming and Scripting

Reading from blocking fifo pipe in shell script

Hi!! I have a problem reading from a fifo pipe in shell script. The idea is simple, I have a C program with two pipe files: An input pipe I use to send commands in shell script to the C program (echo "command" > input.pipe) An output pipe that I read the result of the command also in... (4 Replies)
Discussion started by: victorin
4 Replies

8. IP Networking

blocking DHCP

I've got a legit DHCP server on my network. I've got a 3550 as my VTP server providing 4 vlans to 4 2950 switches. If somebody were to plug into one of those vlans with a DHCP server configured then it would throw off my whole network. How could i block the DHCP server that could plug into the... (2 Replies)
Discussion started by: byblyk
2 Replies

9. IP Networking

School Blocking

I'm in highschool. They blocked my favorite site. How do I disable websense without getting caught on that particular webpage? Is it even possible? *twitch* I would also like to get as much UNIX for beginners information, so if someone might point me in the right direction so I don't have to read... (1 Reply)
Discussion started by: Satine
1 Replies

10. UNIX for Dummies Questions & Answers

blocking domains

Dear All , Kindly note I have sun solaries 7 . I want to block a domain who keep sending emails to my domain and users . thanks (1 Reply)
Discussion started by: tamemi
1 Replies
Login or Register to Ask a Question