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

  • SEARCH
  • Home
  • 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 828065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:40:22+00:00 2026-05-15T03:40:22+00:00

I am having problem debugging why n_bytes in read_from_fifo function in client.c doesn’t correspond

  • 0

I am having problem debugging why n_bytes in read_from_fifo function in client.c doesn’t correspond to the value written to the fifo. It should only write 25 bytes but it tries to read a lot more (1836020505 bytes (!) to be exact). Any idea why this is happening?

server.c:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <signal.h>
#include <pthread.h>
#include <sys/stat.h>

typedef enum { false, true } bool;

//first read the int with the number of bytes the data will have
//then read that number of bytes
bool read_from_fifo(int fd, char* var)
{
    int n_bytes;
    if (read(fd, &n_bytes, sizeof(int)))
    {
        printf("going to read %d bytes\n", n_bytes);
        if (read(fd, var, n_bytes))
            printf("read var\n");
        else {
            printf("error in read var. errno: %d\n", errno);
            exit(-1);
        }
    }

    return true;
}

int main()
{
    mkfifo("/tmp/foo", 0660);
    int fd = open("/tmp/foo", O_RDONLY);
    char var[100];
    read_from_fifo(fd, var);
    printf("var: %s\n", var);
    return 0;
}

client.c:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>

typedef enum { false, true } bool;

//first write to fd a int with the number of bytes that will be written afterwards
bool write_to_fifo(int fd, char* data)
{
    int n_bytes = (strlen(data)) * sizeof(char);
    printf("going to write %d bytes\n", n_bytes);
    if (write(fd, &n_bytes, sizeof(int) != -1))
        if (write(fd, data, n_bytes) != -1)
            return true;
    return false;
}


int main()
{
    int fd = open("/tmp/foo", O_WRONLY);
    char data[] = "some random string abcdef";
    write_to_fifo(fd, data);
    return 0;
}

Help is greatly appreciated. Thanks in advance.

  • 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-15T03:40:22+00:00Added an answer on May 15, 2026 at 3:40 am

    I have found the solution myself.

    The problem is a ‘)’ believe it or not. The n_bytes variable is correct, the problem is that I am not writing that to the fifo.

    this (write(fd, &n_bytes, sizeof(int) != -1))

    should be this (write(fd, &n_bytes, sizeof(int)) != -1)

    Thanks anyway for your answers.

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

Sidebar

Ask A Question

Stats

  • Questions 516k
  • Answers 516k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Linux running on machines without a MMU (memory management unit)… May 16, 2026 at 6:47 pm
  • Editorial Team
    Editorial Team added an answer Your node struct contains a member variable of type Polynominal,… May 16, 2026 at 6:47 pm
  • Editorial Team
    Editorial Team added an answer Now that a code sample is provide, I'm rewriting my… May 16, 2026 at 6:47 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm having a bit of a problem because neither Javascript nor ActiveX (written in
I have spent hours on a debugging problem only to have a more experienced
Iam having problem creating postgresql function in plperl CREATE OR REPLACE FUNCTION zm_json (TEXT,
I'm having a problem comparing strings in a Unit Test in C# 4.0 using
I seem to be having a problem with a macro that I have defined
I'm having a tricky debugging issue, perhaps due to my lack of understanding about
Having problem understanding Delegate error. Error says expression expected, How do I fix? Thanks
I'm having problem accessing the usual properties like frame, bounds, origin, size, etc etc.
I'm having problem at mipmapping the textures on different hardware. I use the following
I am having problem uplaoding file, here are my codes: Any help? Thanks! test.html

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.