Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8249385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:31:36+00:00 2026-06-07T23:31:36+00:00

I’m currently studying IPC, I have a first program A: Do an exec for

  • 0

I’m currently studying IPC, I have a first program

A: Do an exec for B and wait

B: Receive through a fifo a string from a third program “C” and have to resend it to A

I was thinking to open a pipe in A before the exec, then passing fd[1] to B as an argument

if(pipe(fd)==-1){
    perror("Pipe Failed");
    myExit(EXIT_FAILURE);
}

close(fd[1]);   
sprintf(fdString,"%d",fd[1]);

    .......

if((int)(pid=fork())>0)

    waiting(status);    

else if(pid==0){    

    close(fd[0]);   

    execl("./B","B",fdString,(char*)0);
    perror("Exec failed");
    myExit(EXIT_FAILURE);

}

Then in B:

int fd=atoi(argv[1]);

    //Receive string from C 

    len=strlen(string)+1;

if(write(fd,&len,sizeof(int))==-1){
    perror("Error on writing length");
    exit(EXIT_FAILURE); 
}

if(write(fd,string,len)==-1){
    perror("Error on writing string");
    exit(EXIT_FAILURE);     
}

My problem now is reading this string in A. I was thinking something to send a SIGUSR1 to A as soon as the string is written by B on the pipe and having in A something like:

signal(SIGUSR1, signalHandler);
    ........
    static void signalHandler(int signo){
    switch(signo){
    case SIGUSR1:
        listen();
        break;
    default: break;

    }
}
    ........
static void listen(){

    int len;

    if(read(fd[0],&len,sizeof(int))<sizeof(int)){
        perror("Error reading len");
        myExit(EXIT_FAILURE);   
    }

    char string[len];

    if(read(fd[0],&string,len)<len){
        perror("Error reading string");
        myExit(EXIT_FAILURE);   
    }
    printf("String: %s with length %d\n", string, len);
}

However what I get is “Error reading len: Success” , what’s wrong ?

Sorry if my English is bad, any help is appreciated, thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T23:31:37+00:00Added an answer on June 7, 2026 at 11:31 pm

    The program that writes the string is very likely to be segfaulting because of this line:

    if(write(fd,&string,len)==-1) { /* ... */
    

    As you should pass string whithout the &.

    On the other hand, your error message is not very informative because read() is probably returning 0 or less than sizeof(int) bytes. It will only set errno when the return value is -1. The fact that read() returns 0 or less than expected usually means an end of file condition, i.e. the other end has closed the pipe.

    You should fix these issues before trying to dig any further.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a text area in my form which accepts all possible characters from
I am currently running into a problem where an element is coming back from
Does anyone know how can I replace this 2 symbol below from the string
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.