Struggling with mkfifo


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Struggling with mkfifo
# 1  
Old 04-14-2004
Question Struggling with mkfifo

Gurus,

I did my research (on google, this site and my local library) but I am *still* lost. I am trying to teach myself about `named pipes` playing around with MKFIFO (Why not?).

(1) It seems MKNOD is reserved to ROOT whereas MKFIFO is accessible to all users. Am I correct? If the answer is `yes,` can someone explain why? Based on what I read, both commands seem to produce the same results...

(2) I can create a fifo on a empty file e.g. `mkfifo empty_file` but when I attempt to edit it in VI (as myself or another userid), my editor never comes up. Is it because the blocking nature of the named pipe I created?

(3) It seems that when a process (here, VI) reads from a named pipe that has no data in it (here, `empty_file), the reading process is blocked. Fine. So, how do I write to it??

(4) Why can't I create a fifo out of an already existing file? Is it possible if I specify the correct mode e.g. `mkfifo already_existing_file +RW...`?

(5) Where can I find more *detailed* info about this topic?

Thanks in advance to all for sharing your knowledge. Al.

PS: I am on HP-UX B.11.00 U 9000/800.
# 2  
Old 04-14-2004
Quote:
This does not make a lot of sense.
So-rry your Unix-ness...Smilie I should have been more specific & I apologize: I'm still very new to Unix. I meant to say that on the machine I work on, I (as a user) can only use MKFIFO.

If I do `mknod bla`, I get an error message "mknod: must be super-user". BTW, I tried to do the same thing as you did: it did not work.

[dev1@la]/home/dev1% mknod bla p
[dev1@la]/home/dev1% cat bla &
[2] 23119
[dev1@la]/home/dev1% echo "hello world" > bla
ksh: bla: cannot create

I am working in my /home directory. What am I doing wrong?
# 3  
Old 04-14-2004
if a user was allowed to mknod he woudl be able to create his own device files and could potentially really mess things up for an administrator.

mkfifo allows you to create a buffer area that is read by different process.

mknod is very strong. i would put it up there w/ allowing a user to issue adn execute the format utility.
# 4  
Old 04-15-2004
I've been looking over my documentation for early versions of unix. The mknod system call and the mknod utility are restricted to root only until the arrivial of named pipes. When unix has named pipes, both the mknod system call and the mknod utility make an exception that allows anyone to create named pipes. I can't find a counter example to this, but I can accept that alan has found one.

I too am interested in which version of unix that alan is using. Alan since you are new to unix, you may not yet know about the uname command. "uname -a" is a command that will tell us about your version of unix.

As for mkfifo, both the function and utility seems to have come from posix. Originally, it seems, posix did not support mknod as being too unix-like. But it looks like mknod is there now, so i guess that they got over it.

Now concerning this:

[dev1@la]/home/dev1% echo "hello world" > bla
ksh: bla: cannot create

Before ksh can run the echo command, it must open bla. I would interpret this as ksh decided that it must create "bla" and was not succeeding. That would be very odd since the preceding "cat bla" seems to have worked.

alan, since mknod was not working for you, why did you use it in the example you posted? Were you running as root? Did you try the mkfifo command instead? Also after you create bla, run the command "ls -l bla" and post the results of that.
# 5  
Old 04-15-2004
mkdir() preceded posix. When mknod() creates a directory, it is truly emply. It takes two link() calls to create the . and .. entries. This leaves a window where the directory has an illegal structure. This caused race conditions and if the program died before the link calls succeeded, the filesystem was left in an illegal state. Ordinary users had to invoke a suid program to make directories, in part to ensure that the links were at least attempted.

That's why the mkdir() system call was created...it atomically creates a valid directory in one system call. And user programs can invoke it. The mkdir utility no longer needs to be suid.

mknod() has been deprecated for creating directories for some time.
# 6  
Old 04-15-2004
Quote:
I too am interested in which version of unix that alan is using. Alan since you are new to unix, you may not yet know about the uname command. "uname -a" is a command that will tell us about your version of unix.
I am familiar with `uname -a`: I put my OS info in my first post but I guess it got lost in the clutter. I am on HP-UX B.11.00 U 9000/800.

Quote:
Were you running as root? Did you try the mkfifo command instead? Also after you create bla, run the command "ls -l bla" and post the results of that.
I am NOT running as root. I know nothing about my user ("dev1") permissions but I am certain that I don't have super-user privilege. I have tried to use both `mknod` and `mkfifo`in my /home directory but to no avail:


[dev1@la]/home/dev1% mkfifo bla
[dev1@la]/home/dev1% cat bla &
[1] 10907
[dev1@la]/home/dev1% echo "hello world" > bla
ksh: bla: cannot create

[dev1@la]/home/dev1% ls -l bla
prw-rw-r-- 1 dev1 cadev 0 Apr 15 10:43 bla|
[dev1@la]/home/dev1%


I got the same error msg when I use "mknod". Obviously (see the "p"), I am able to create my fifo but it is as far as I can go.

I am confused: If I look at the permission bits, it seems that my fifo is usable by my userid for read/write, correct?

Can this be related to my user permissions? How can I know which those are? I have no super-user privileges so SAM is not accessible...
# 7  
Old 04-15-2004
Oh, BTW (re: 'Struggling with mkfifo')

Just in case you're wondering why I am bothering with MKFIFO, MKNOD etc... is for the following reason:

I want to uncompress/compress a database binary (export) file and import/export the output into difference instances of my database simultaneously. I know that this can be done using a "named pipe" alongside with un/compress being run in the background.

That's what I am trying to accomplish. FYI.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parsing file: struggling against sed command

Hello fellows, Sure you can help this poor guy that is struggling against sed command, being unable to tame it I have a lot of files like this: From this one, I need to obtain values highlighted in bold/red To do so, I am executing this piece of code inside a loop: ... (10 Replies)
Discussion started by: manolain
10 Replies

2. UNIX for Dummies Questions & Answers

Struggling to combine two Greps statements

Greetings! I have been tasked to create a report off files we receive from our hardware suppliers. I need to grep these files for two fields 'Test_Version' and 'Model-Manufacturer' ; for each field, I need to capture their corresponding values. When running each statement separately, I get... (4 Replies)
Discussion started by: alan
4 Replies

3. Homework & Coursework Questions

Help with Mkfifo and exec

Hello guys! I am doing a project for the university and I have to do that a process has to create several children through fork(). The father process sends a pathname to each one through exec and the children must send to the father a list with the files from each directory. The father... (1 Reply)
Discussion started by: dano88
1 Replies

4. Programming

Help with Mkfifo and exec

Hello guys! I am doing a project for the university and I have to do that a process has to create several children through fork(). The father process sends a pathname to each one through exec and the children must send to the father a list with the files from each directory. The father is... (1 Reply)
Discussion started by: dano88
1 Replies

5. Shell Programming and Scripting

Struggling with AWK

I know this is an easy problem, but I've been struggling with it all morning and finally admit I need help. I have two files that I need to compare. After doing this the easy way (grep -F) I realize that there are other fields in file2 that match field1 in file1, so I turned to awk. I want to... (7 Replies)
Discussion started by: moldoverb
7 Replies

6. Shell Programming and Scripting

Struggling with arrays and delimited file

Hi, I am trying to use arrays in my script but can not seem to get it to work. I have a file called sections, this contains headers from a tripwire log file, separated by "@" but could be "," if easier The headers will be used to cut sections from the log file into another to be mailed. ... (5 Replies)
Discussion started by: pobman
5 Replies

7. Shell Programming and Scripting

struggling within awk

!#/bin/bash cat input.sh | awk ' { cur1=tolower($1) cur2=tolower($2) rsh $cur1 report | grep $cur2 # i just want to make the code line to work } ' the error which i get is .... ./madh1.sh: line 1: !#/bin/bash: No such file or directory awk: cmd. line:13: rsh $cur1 report |... (4 Replies)
Discussion started by: geeko
4 Replies

8. UNIX for Advanced & Expert Users

Help- Unix File Compare- Struggling

I had posted this earlier about 3 weeks ago and had recieved a response and I did sort both the files and the comm command is still not working. Can someone please assist me, I would really appreciate it. Below is what I am trying to do I need to compare File A with File B and create FILE C... (2 Replies)
Discussion started by: guiguy
2 Replies

9. Shell Programming and Scripting

Struggling with a text file

Hi, I am struggling with the following... I try to grep out information of a text file I got with lynx, a text browser. The text file I get from lynx with dump is attached in the bottom. What I would like to get is another file containing the astro-ph/98324 (number) and title and list of... (13 Replies)
Discussion started by: pau
13 Replies

10. UNIX for Dummies Questions & Answers

struggling with addusr ...

I'm completely new to UNIX, and having got the hang of directory navigation / creation (Just about), I think it is time to create an FTP account, so that I can upload a web site remotely. Herein lies the problem... 1: I cannot find a breakdown of addusr commands, so I cannot create a... (2 Replies)
Discussion started by: Dufty
2 Replies
Login or Register to Ask a Question