🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.sequent
Article #373

Re: How do you distribute file descriptors?

#373
From: Keyvan Shirnia Pre Sales
Date: Tue, 06 Nov 1990 18:30
73 lines
4063 bytes
In article <1990Nov6.015433.10642@mathrt0.math.chalmers.se> augustss@cs.chalmers.se (Lennart Augustsson) writes:

>In a language implementation that I am doing I've got the following
>problem: I'm using multiple processes (processors) to run a program,
>during the execution of the program it may be necessary to open files
>(and sockets).  After a file has been opened it would be desirable
>if all processes (and not just the one doing the open) could read from
>that file (the reason for this is to keep all processes "equal").
>I can see no clean solution to this problem.  The descriptor that the
>opening process gets back needs to be distributed to the others
>somehow, but as far as I know there is now mechanism for that.  Or is
>there?

Well, if all your processes are running on the same machine, you do not
need to use sockets. I think a better solution would be to use pipes.
(Although pipes are built using socketpair() system call!! ;-)

So the idea is something like this: (!)

When spawning its processes, the parent  can also open up pipes between
itself and its children. Then by simply using read() and write() system calls
you can transfer data between your processes.  If you don't want the children
to hang around the read() system call (block for data to be written to the
pipe) then I'm afraid you have to use signals. (ie. send a signal to the 
child process when you know you are about to send the data to the child)

Not a very pretty sight!! ;-)

>4.3 BSD Unix contains a way to distribute file descriptors through the
>sendmsg and recvmsg system calls, but as usual Sequent are years
>behind when it comes to the operating system (sendmsg&recvmsg can send
>file descriptors in the UNIX domain on vanilla 4.3 BSD, Ultrix, and
>SunOS).

Can I just say something here! You mentioned you would like to distribute
the file descriptors between your processes. I think it is worth mentioning
the fact that you have to send the filename to the children. It's the children's
job to open files and get appropriate file descriptors. 

The child as a process has its own user space, which is totally seperate from 
its parent. So the child is totally unaware of the fact that the parent has 
just opened a file, and updated its user space file table. However, if the
parent opened up the file before spawning any processes, the children will
inherit the parents file table including the file descriptors.

sendmsg and recvmsg are just equivalent to write() and read() on pipes,
respectively.

>(I have another solution using signals in mind, but I don't like it.)

You have to be very wary  when using signals. Its very easy to get mixed up
with all the processes talking to each other using signals.

Just for your information, this task under ATT's inter process communication 
is very much simpler. All you need to do, is to setup a shared memory segment, 
and lock the segment using semaphores. This way the parent has control over the
children and can indicate when they should read data from the shared memory.
NOTE: you would still have to use signals, if the children are unable to block
on the semaphore lock.



I hope this helps.

Best regards,
Keyvan

P.S. If you have any more questions regarding this, please Do ask!! ;-)

      -m------- Keyvan Shirnia		       Tel : +44 252 373035
    ---mmm----- Pre Sales Support 
  -----mmmmm--- Pyramid Technology Ltd.        keyvan@pyra.co.uk
-------mmmmmmm- Farnborough GU14 7NA, England.
Technical Details
Message-ID: <657916216.AA4508@flaccid>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!pyrltd!pyra.co.uk!keyvan
References: <1990Nov6.015433.10642@mathrt0.math.chalmers.se>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!pyrltd!pyra.co.uk!keyvan
From: keyvan@pyra.co.uk (Keyvan Shirnia Pre Sales)
Newsgroups: comp.sys.sequent
Subject: Re: How do you distribute file descriptors?
Message-ID: <657916216.AA4508@flaccid>
Date: 6 Nov 90 18:30:11 GMT
References: <1990Nov6.015433.10642@mathrt0.math.chalmers.se>
Sender: news@pyra.co.uk (News system)
Reply-To: keyvan@pyra.co.uk (Keyvan Shirnia)
Organization: Pyramid Technology Ltd, Farnborough, ENGLAND
Lines: 73