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 4602396
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:58:41+00:00 2026-05-21T23:58:41+00:00

I’m writing a program that has a number of child processes. The parent has

  • 0

I’m writing a program that has a number of child processes. The parent has two pipes to write to the child, each pipe is dup2ed into a separate file descriptor in the child. The parent reads through a script file with a number of commands to work what it needs to do. This seems to work fine except I’ve noticed that if I try to close a pipe from parent to child then if the next line in the script file is fully blank it will be read in weirdly. If I print it out then it comes out as ���< which my program (understandably) doesn’t know what to do with.

There is seemingly no link at all between the file pointer that I’m reading in from and the pipe that I’m closing.

My code for reading in lines in is below. It works perfectly normally, just in this case it doesn’t work properly and I can’t work out why.

char *get_script_line(FILE *script)
{
    char *line;
    char charRead;
    int placeInStr = 0;
    int currentSizeOfStr = 80;
    int maxStrLength = 64;

    /* initialize the line */
    line = (char *)malloc(sizeof(char)*currentSizeOfStr);

    while ((charRead = fgetc(script)) != EOF && charRead != '\n') {
        /* read each char from input and put it in the array */ 
        line[placeInStr] = charRead;
        placeInStr++;
        if (placeInStr == currentSizeOfStr) {
            /* array will run out of room, need to allocate */ 
            /* some more space */ 
            currentSizeOfStr = placeInStr + maxStrLength;
            line = realloc(line, currentSizeOfStr);
            }
    }

    if (charRead == EOF && placeInStr == 0)
    {
        /* EOF, return null */
        return NULL;
    }

    return line;
}

And when I close a pipe I’m doing this:

fflush(pipe);
fclose(pipe);

Does anyone have any idea of what I might be doing wrong? Or have some sort of an idea of how to debug this problem?

edit: To be clear my input script might (basically) look something like this:

Start a new child and set up pipes etc
Send EOF to one of the pipes to the child
(BLANK LINE)
Do something else

It works fine otherwise and I’m fairly sure I’m closing the pipes as I’m doing will send EOF as its supposed to.

  • 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-05-21T23:58:41+00:00Added an answer on May 21, 2026 at 11:58 pm

    Actually.. think I just fixed it. I wasn’t freeing the line in get_script_line when I was done with it but once I put that in it has all started working correctly. I have no idea why that would have an effect though.. would be interested if anyone could tell me why not freeing memory could have that effect?

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I need a function that will clean a strings' special characters. I do NOT
I am writing an app with both english and french support. The app requests
I'm trying to create an if statement in PHP that prevents a single post

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.