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?
Printable View
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?
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.
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).
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.
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.