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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:25:53+00:00 2026-06-04T01:25:53+00:00

I have two simple programs that use named pipes, here is the first: int

  • 0

I have two simple programs that use named pipes, here is the first:

int main(int argc,char **argv)
{
  if (argc<2)
   error_nsys_f("usage: [fifo]");

  if (mkfifo(argv[1],S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH)<0)
   error_sys_f("error while creating named pipe");

  int fd=open(argv[1],O_RDONLY);
  int log_file=open("wyniki.log",O_WRONLY | O_CREAT| O_TRUNC,S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
  long result;
  size_t len;
  if (fd<0)
   error_sys_f("error while openning pipe");
  if (log_file<0)
   error_sys_f("error while openning log file"); 
  //unlink(argv[1]);
  char path[MAXLINE];
  char buffer[BUF];
  while(1)
  {
   if (read(fd,&len,sizeof(size_t)) == -1)
   {
       cleanup(fd,argv[1]);
       error_sys_f("error while reading from file-name queue");
   }
   if (read(fd,path,len) == -1) 
   {
       cleanup(fd,argv[1]);
       error_sys_f("error while reading from file-name queue");
   }
   result=count(path,buffer);
   if (result>-1)
   {
       sprintf(buffer,"%s: %ld\n",path,result);
       if (write(log_file,buffer,strlen(buffer)) == -1)
       {
        cleanup(fd,argv[1]);
        error_sys_f("error while writing to log-file");
       }
   }
  }
}

and the second one

int main(int argc,char **argv)
{

 if (argc<3)
     error_nsys_f("usage: [fifo] [plik1] [plik2]...\n");

 int fd=open(argv[1],O_WRONLY);
 int i;
 int s;
 if (fd<1)
     error_sys_f("nie udalo sie otrzymac dostepu do kolejki");

 for(i=2;i<argc;++i)
 {
     s=strlen(argv[i])+1;
     if (write(fd,&s,sizeof(size_t)) == -1)
     {
      close(fd);
      error_sys_f("error while writing to queue");
     }
     if (write(fd,argv[i],strlen(argv[i])+1) == -1)
     {
      close(fd);
      error_sys_f("error while writing to queue");
     }
 }
 close(fd);
 return EXIT_SUCCESS;
}

in the second program I give him the name of the fifo to write to and names of the files, in the first one I read the length of name and file-name, count the bytes and write it to log-file.

But there is a problem, if I try to write for example one file name to the fifo, the first program reads the name and the length ok, preforms the counting but after that he reads the same file-name all the time from fifo. He behaves like he didn’t remove the message read from fifo. What is the cause of this?

  • 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-04T01:25:55+00:00Added an answer on June 4, 2026 at 1:25 am

    You are not handling the case where read() returns 0 , which means there is no more data and the other end has closed the pipe.

    So your code should stop looping if read() returns 0 as well, not just when it returns -1

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

Sidebar

Related Questions

I have two very simple, identical UITableViews in my app that are populated with
I have these two simple files that define a C++ class with a tryME
I have a grid view that has two simple columns, a report number and
Let's say I have two strings like this: XABY XBAY A simple regex that
I have the following code that fills dataTable1 and dataTable2 with two simple SQL
I have program with two files; main.py that has my main logic and class.py
Let's say I have two simple models project t.string :title vote t.references :project t.integer
I have two geo-spatial simple convex polygon areas, in latitudes and longitudes (decimal degrees)
Question is simple: I have two List List<String> columnsOld = DBUtils.GetColumns(db, TableName); List<String> columnsNew
I am trying to design a simple application where in I have two entities

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.