Find the answer to your Linux question:
Results 1 to 7 of 7
3. Are the multi-tasking capabilities in Linux (inter process communication) only valid for processes spawned from within a single executable? For example can two independent executables share semaphores etc?...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2009
    Posts
    8

    Understanding Linux Processes 3


    3. Are the multi-tasking capabilities in Linux (inter process communication) only valid for processes spawned from within a single executable? For example can two independent executables share semaphores etc?

  2. #2
    Linux Engineer hazel's Avatar
    Join Date
    May 2004
    Location
    Harrow, UK
    Posts
    1,207
    I don't know about semaphores but any two processes can communicate through a pipe. If they aren't closely related, you need a named pipe or fifo, which is a kind of pseudo-file; you create it with mkfifo. Then all that is needed is for both programs to know the name of the pipe. And any two programs can communicate through sockets.
    "I'm just a little old lady; don't try to dazzle me with jargon!"
    www.hrussman.entadsl.com

  3. #3
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,525
    Quote Originally Posted by josephstein View Post
    3. Are the multi-tasking capabilities in Linux (inter process communication) only valid for processes spawned from within a single executable? For example can two independent executables share semaphores etc?
    Again, I think you are confusing processes with functions. All Linux IPC mechanisms are valid between any 2 (or more) processes, including pipes, semaphores, queues, sockets, or shared memory. Sharing can be restricted, and pipes or sockets generally only work between two processes (though a single process can pipe data to itself or communicate with itself thru a socket). In any case, any process can spawn (fork/exec) any number of sub-processes (each an independently scheduled execution unit) or threads (lightweight processes, intimately associated with the starting process).
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  4. #4
    Just Joined!
    Join Date
    Sep 2009
    Posts
    8
    Quote Originally Posted by hazel View Post
    I don't know about semaphores but any two processes can communicate through a pipe. If they aren't closely related, you need a named pipe or fifo, which is a kind of pseudo-file; you create it with mkfifo. Then all that is needed is for both programs to know the name of the pipe. And any two programs can communicate through sockets.
    So if you run 2 executables say ./exec1 and ./exec2 from a bash shell, and they have knowledge of names of pipes created from one or the other, they can communicate with each other. And this is treated equivalently to a single executable say ./exec3 that contains a fork() call that splits into two processes that also communicate with each other through similar named pipes?

  5. #5
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,525
    Quote Originally Posted by josephstein View Post
    So if you run 2 executables say ./exec1 and ./exec2 from a bash shell, and they have knowledge of names of pipes created from one or the other, they can communicate with each other. And this is treated equivalently to a single executable say ./exec3 that contains a fork() call that splits into two processes that also communicate with each other through similar named pipes?
    You should read the man pages for popen and pipe. If you use the pipe() function, then you will need to fork your process so the child process can access the input fp. This is possible because when a process forks, the child inherits all open file descriptors (for files, sockets, pipes, etc). If you use popen(), then the popen() call will fork and execute a shell with your command and that command's stdin will be the end point of the pipe FILE* returned by popen() to the caller.

    FYI, Linux/Unix don't have named pipes such as are found in Windows systems.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  6. #6
    Linux Engineer hazel's Avatar
    Join Date
    May 2004
    Location
    Harrow, UK
    Posts
    1,207
    Quote Originally Posted by Rubberman View Post
    FYI, Linux/Unix don't have named pipes such as are found in Windows systems.
    What about fifos then? Aren't they named pipes?
    "I'm just a little old lady; don't try to dazzle me with jargon!"
    www.hrussman.entadsl.com

  7. #7
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,525
    I suppose you could say that. They do serve the same purpose, though they are part of the OS file system. I usually use message queues for applications that might use fifo's, so I am not too familiar with their use. Thanks for reminding me about them. I can see their utility for applications that don't want to deal with message queues.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •