francois@chorus.fr (Francois Armand) (08/20/90)
I am looking for some _real_ _uses_ of current offset sharing by real applications running on any flavor of UNIX systems. To be more precise, suppose you have a program that opens(2) a file "foo" for read/write operations, and then forks(2).The parent and the child processes now share the same open file description, and in particular the current offset within the file and the flags (O_SYNC, O_APPEND, O_NDELAY...). It seems to me that if both the parent and the child want to make any sensible use of that shared access to the file, they need to synchronize themselves by some mechanism (signals, shared memory, file locks...). In addition, within the Unix file system sources which I have read, I have never seen any "synchronization" mechanism to provide a deterministic way of computing the current offset when, for example, two read(2) operations are issued in parallel by two processes sharing the same open file. Thus, I really wonder how one could deal without any synchronization between user's programs. I have never seen any program using this property! Thus, my question is: do Unix systems really need to make the current offset be shared between parent and child processes. I would like to know if somebody has ever seen or written an application using that property of the UNIX fork(2)... I am not interested in having example of applications sharing open files such as terminals, pipes or sockets (for which current offset is meaningless). Could you mail me a description of the examples you are aware of, I will summarize to the net. I would be happy to get detailed information about the use of the mechanism, ie: why is the application written that way, how processes synchronize themselves, what flags are set for the shared open files (for example, setting the O_APPEND flag, changes the behaviour of the current offset...), do the programs use lseek(2)... and any kind of information that may be relevant. Thanks in advance Francois ARMAND Francois ARMAND Chorus Systemes Tel: +33 (1) 30 57 00 22 6 Avenue Gustave Eiffel Fax: +33 (1) 30 57 00 66 78182 St-Quentin-en-Yvelines Cedex Email: francois@chorus.fr (Internet) FRANCE
peter@ficc.ferranti.com (Peter da Silva) (08/22/90)
In article <6011@chorus.fr>, francois@chorus.fr (Francois Armand) writes: > I am looking for some _real_ _uses_ of current offset sharing > by real applications running on any flavor of UNIX systems. Here's one from a script I use in mail handling: { echo "An error occurred on `net lname` while attempting to forward mail." echo "It was not possible to forward the mail to $SYS for further handling." echo "(it is possible that $SYS was down, or temporarily off the network," echo " so please try again in a few minutes)" echo "" echo "Your mail was not delivered to $USERS" if [ -s $TMP ] then echo "" echo "The following messages were returned from the delivery program:" echo "==========" cat $TMP echo "==========" fi echo "" echo "Here are the contents of the lost mail:" echo "==========" cat } > /tmp/err$$ > I have never seen any program using this property! Now you have. It's used all over in shell scripts. In fact, in Version 6 UNIX this is how control structures in shell scripts were implemented: "if" and so on were loadable programs, that seeked on the open file descriptor for the script looking for labels. -- Peter da Silva. `-_-' +1 713 274 5180. 'U` peter@ferranti.com