How to properly connect these three processes using pipes?
I'm trying to properly connect three processes in order to allow inter-process communication between them. I have one process, scanner, which takes the parent's STDIN and then processes the words within the stream. If a word length is odd, it sends it to one process, if it is even, it sends it to another. These processes should take in these words via STDIN (I assume) and then output some info back to the scanner process via STDOUT. The STDOUT of even/odd should be redirected to scanner, which will then read (using read) and then output/process the words. It's an academic exercise, not a practical one. Here's what a picture of it would look like:
And here's what my code looks like (with some stuff omitted):
My problem is that I don't know how to properly use dup2 and close. Currently scanner will receive the proper stdin, but I don't think its redirecting its stdout properly. Do I need to redirect that for this, because in scanner, I write to each respective even/odd process like so (I use the file descriptors as passed to it from the main program, as demonstrated above:
Any feedback/advice/etc would be greatly appreciated! I'm extremely close to finishing- it's just the plumbing that eludes me.
You had the right idea but you're never calling pipe(). So that wouldn't work no matter what you do.
Of course, with four sets of pipes to deal with, you're inevitably going to end up blocking if you don't use something like select() to inform you when any of them are ready to be read or written -- when reading or writing to them won't cause your program to stall. You should set them nonblocking, too.
How about the full-fledged example I just posted for you, something wrong with it?
I think your problems had to do with catch-22 situations though -- you waiting for process 1 to read, while process 1's waiting for you to read from it... That's why you need to use select(), since it can wait for multiple sets of descriptors at once, and tell you which of them needs to be dealt with.
There's nothing wrong with your example. The problem is that I have three processes that are forked off the main process. I should have perhaps been a bit clearer specifying that. I will look into select- that might solve the trick. I do use a signal from the even/odd subprocesses to tell the scanner when it's done processing input and wants to write information. The problem is that even/odd never receives input on its standard input.
Have your scanner process do that forking then, instead of main.
You could even make it its own application instead of part of main.
I have scanner as its own application:
if(execl("./scanner", "scanner", stoeven, stoodd, eventos, oddtos, NULL ) == -1) { printf("execl Error!"); exit(1); }
The problem is that when scanner forks, I want to be able to write to even/odd and then receive from even/odd (so there are three distinct processes- all of the code from below is from another driver program, so I guess when I execute the driver there are four processes). Would it be better to move the even/odd forks under the scanner fork? I cannot fork inside of the scanner program (restraint given to me).
Greetings Experts,
I am working for a bank client and have a question on connect-direct and SFTP.
We are using Linux RedHat servers. We use connect-direct to transfer (NDM) files from one server to another server. At times, we manually transfer the files using SFTP from one server to another... (2 Replies)
It appears i cant connect linux VPS server via SSH or i cant SCP any file to it and i cant wget any file TO it (from inside it) while CSF (Config Server Firewall, LFD is running. Just after isntall in default configuration and after changing TESTING mode to LIVE mode.
Trying to wget & install... (1 Reply)
We have a production server at a client site running AIX. And recently when users are trying to connect to it via telnet, it prompts "No more multiple IP addresses to connect".
Can I know what does this error mean? and how to rectify this?
Thanks. (2 Replies)
I am trying to get a better understanding of pipes and processes. I have code in which I link 3 processes A,B,C. I have A->B->C but how would I go about getting C->A?
Here is my code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
main()
{
pid_t A, B, C;
int fd;
int fd2;
... (1 Reply)
I need help with understanding this in C-programming style(the systemcalls only):
Three processes communicates via two pipes. (when the processes creates all stdin is the keyboard and all stdout is the screen)
This is how the communication goes:
Process 2 stdin (keyboard) and stdout goes via... (3 Replies)
I had issues with processes locking up. This script checks for processes and kills them if they are older than a certain time.
Its uses some functions you'll need to define or remove, like slog() which I use for logging, and is_running() which checks if this script is already running so you can... (0 Replies)
Hi All,
I am running 25 background process from a Unix shell script which calls a single Oracle procedure with different paramenters each time.
These 25 process creates 25 different files.
When i run these 25 Background SQLPLUS processes, few files are not created completly but if i run 25... (1 Reply)
Hi
Is there an easy way to identify and group currently running processes into OS processes and APP processes. Not all applications are installed as packages.
Any free tools or scripts to do this?
Many thanks. (2 Replies)
Is there a way to monitor certain processes and if they hang too long to kill them, but certain scripts which are expected to take a long time to let them go?
Thank you
Richard (4 Replies)