Sponsored Content
Top Forums Programming Pipes connecting 3 processes in a "circle" Post 302500892 by tfarmer4 on Wednesday 2nd of March 2011 12:56:02 AM
Old 03-02-2011
Network Pipes connecting 3 processes in a "circle"

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:

Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
main()
{
pid_t A, B, C;
int fd[2];
int fd2[2];

if (pipe(fd) == -1)
{
    perror("pipe");
    exit(1);
}
B = fork();
if (B == -1)
{
    perror("fork");
    exit(2);
}
if (B == 0)
{
    if (pipe(fd2) == -1)
    {
        perror("pipe");
        exit(11);
    }
    C=fork();
    if(C == -1)
    {
        perror("fork 2");
        exit(22);
    }
    if (C == 0)
    {
        //i am C
        //do some stuff
    }
    else
    {
        //i am B
        //do some stuff
    }
}
else
{
    //i am A
    //do some stuff
}

 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

2. UNIX for Advanced & Expert Users

problem using pipes with "ls"

Hi all, I tried the following command $ find / -name xyx | ls -l so logically it should show the listing of directory xyz , assuming there's only one instance of xyz . But the above command shows the listing of current directory instead. I got the desired result using it in the... (4 Replies)
Discussion started by: bijeet_sunny
4 Replies

3. UNIX for Dummies Questions & Answers

Do pipes know when they have to "wait" for all the data?

Hi, I was wondering if pipes ("|"), or rather the command that follow them, know when they're supposed to wait for all the data? For instance, if you take this: cat my_file | sort | uniq for uniq to work well, it needs to have rows sorted, but for lines to be sorted properly, it needs... (5 Replies)
Discussion started by: a.brassac
5 Replies

4. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

5. Shell Programming and Scripting

need to kill a number of processes with name "XYZ" at a time using shell script

Hi, when i grep for the process "XYZ" , there will be some good number of processes with that name, i want to kill all the these processes at a time using shell script? Any help needed for this action. Thanks Regards, Anil (6 Replies)
Discussion started by: anilmanepu
6 Replies

6. UNIX for Advanced & Expert Users

"Network error: No route to host" While connecting guest RHEL4 using putty

Hi, I have installed RHEL4 using vmware workstation.. Host OS: Windows XP Guest OS: RHEL4 Pls refer step 17 & 18 in below link... ORACLE-BASE - Red Hat Enterprise Linux 4 and Centos 4 Installation 1) If i choose to assign IP automatically (using DHCP) means, i am able to connect RHEL4... (3 Replies)
Discussion started by: thomasraj87
3 Replies

7. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

8. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

9. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies
procset(4)						     Kernel Interfaces Manual							procset(4)

NAME
procset.h - Send a signal to one or more processes SYNOPSIS
typedef struct procset { idop_t *p_op; idtype_t p_lidtype; id_t p_lid; idtype_t p_ridtype; id_t p_rid; } procset_t; DESCRIPTION
The contents of the <procset.h> structure define a set of target processes based on logical operations performed on the two sets of poten- tial target processes indicated by the two pairs of id + type parameters, which designate "left" and "right" groups of processes. The log- ical operations supported are the union, intersection, difference, and exclusive OR of the left and right groups. The p_lid and p_lidtype members define one set of potential target processes, the "left" set. The p_rid and p_ridtype members define the "right" set of potential target processes. These parameters work together to select the target process or processes. The value of p_op is used to combine these two groups into the final group of actual target processes: Specifies that the target group of processes consist of the remaining processes in the left set that are not common to the right set. Specifies that the target group con- sists of those processes that are in both sets. Specifies that the target group consists of those processes that are in either set, or in both sets. Specifies that the target group consists of those processes that are in either set, but not in both sets. RELATED INFORMATION
Functions: priocntlset(2), sigsend(2). Files: signal.h(4). delim off procset(4)
All times are GMT -4. The time now is 09:31 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy