Control stript which is runing in background.

Alan Bawden alan at csail.mit.edu
Sat Jan 2 06:30:56 EST 2021


jak <nospam at please.ty> writes:

   Il 02/01/2021 01:07, Alan Bawden ha scritto:
   > jak <nospam at please.ty> writes:
   >
   >     Il 01/01/2021 06:23, Alan Bawden ha scritto:
   >     > jak <nospam at please.ty> writes:
   >     >
   >     >     Running the command:
   >     >
   >     >     $ cat bible.txt > cmdpipe & cat bible.txt > cmdpipe & cat bible.txt > cmdpipe
   >     >
   >     >     the three texts do not mix....
   >     >
   >     > The three texts do not mix as long at the contents of bible.txt is short
   >     > enough (and provided `cat' only calls `write' once).  In the POSIX
   >     > specification, the manual page for the `write' system call describes
   >     > writing to a pipe or FIFO as follows:
   >     >
   >     >    Write requests of {PIPE_BUF} bytes or less shall not be interleaved
   >     >    with data from other processes doing writes on the same pipe.  Writes
   >     >    of greater than {PIPE_BUF} bytes may have data interleaved, on
   >     >    arbitrary boundaries, with writes by other processes, whether or not
   >     >    the O_NONBLOCK flag of the file status flags is set.
   >     >
   > ...  Just to make sure I wasn't missing
   > something, I tested your exact command before I sent my previous reply.
   > They mixed.
   >

   This is really strange. On which system did you test? unix, linux or a
   surrogate (cygwin, msys)? I asked this because bible.txt is 4.25MB size
   (https://github.com/mxw/grmr/blob/master/src/finaltests/bible.txt)...
   and the OP needs to send only commands (I hope smaller than the bible).

I tested it on both Linux and FreeBSD.  My test data was a 289M file I
happend to have handy.  I didn't try to see how much smaller that file
could be to still see mixing, but I can tell you that on FreeBSD
PIPE_BUF is 512 bytes and on Linux PIPE_BUF is 4096 bytes.  Recent
versions of POSIX apparently require PIPE_BUF to be at least 512.  (My
older copy of POSIX doesn't mention any lower bound at all!)

So as long as the OP's commands are no longer than 512 bytes, and as
long as they are careful to send commands in a single call to write(),
and as long as the commands don't require a reply, they can get away
with using a pipe/FIFO.  (Or maybe they can know that there will only
ever be one client.)

-- 
Alan Bawden


More information about the Python-list mailing list