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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:36:24+00:00 2026-05-25T18:36:24+00:00

I have two programs one of which writes some entries into a file and

  • 0

I have two programs one of which writes some entries into a file and the other one reads all the entries from the file an processes them.

Currently, the files are executed sequentially. That means, the first programs produces the file completely and exits before the second program is run. Now I want, without much modifications that the second program can be run simultaneously in a producer-consumer fashion. I know I should use interprocess communication, but at this point I want to make minimal changes the programs to get the running.

Specifically, I want that the second program processes the entries from the second file in real time as they are generated by the first file.

I am using gcc on ubuntu 11.04

  • 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-25T18:36:25+00:00Added an answer on May 25, 2026 at 6:36 pm

    If you are using a Unix-like operating system, may I suggest pipes? Modify your first program to write to standard output (instead of opening a file and passing references that ofstream around, pass std::cout). Modify your 2nd program to read from standard input (ditto, but replace your ifstream references with std::cin).

    Then, instead of

    prog1 -o some-tmp-file.txt
    prog2 -i some-tmp-file.txt
    

    do this:

    prog1 | prog2
    

    EDIT: If your existing programs are based on <cstdio> instead of <iostream>, the same principle applies. Use stdout instead of your existing FILE* in the first program. Uses stdin instead of your FILE* in the second program.


    EDIT #2: If you want to make absolutely no change to the second program, and perhaps only minimal changes to the first program, try using named pipes.

    mkfifo /tmp/some-tmp-file.txt
    prog2 -i /tmp/some-temp-file.txt &
    prog1 -o /tmp/some-temp-file.txt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a spring batch program which reads from a file and writes to
I have a simple spring batch program which reads data from a INPUT file
I have two programs: one CLI program, and one GUI. The GUI is a
I have two begininer programs, both using the 'while' function, one works correctly, and
I have two programs, Writer and Reader. I have a FIFO from Writer to
I have two (UNIX) programs A and B that read and write from stdin/stdout.
I have recently been put in charge of debugging two different programs which will
I would like a batch file to launch two separate programs then have the
Say I have a file, t.txt, that contains the following two lines: one two
I have the following two programs: long startTime = System.currentTimeMillis(); for (int 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.