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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:54:38+00:00 2026-06-03T06:54:38+00:00

I’m looking for the best way to read data from an stdin pipe in

  • 0

I’m looking for the best way to read data from an stdin pipe in C programming.

Problem : I need to seek on this data, ie I need to read data from the start of the stream after reading some data at the end of this same stream.

Small use case : gunzip -c 4GbDataFile.gz | myprogram

Another one :

  1. On local host : nc -l -p 1234 | myprogram
  2. On remote host : gunzip -c 4GbDataFile.gz | nc -q 0 theotherhost 1234

I know that reading from fifo can be done only once. So, at the moment :

  • I slurp everything from stdin to memory and work from this allocated memory.

It’s ugly, but it works. An evident issue is that if someone sends a huge (or a continuous) stream to my app, I’ll end with a big allocated memory chunk or I’ll run out of memory. (Think about an 8Gb file)

What I thought next :

  • I set a size limit (maybe user-defined) of that memory chunk. Once I’ve read this much data from stdin :
    1. Either I stop here : “Errr. Out of memory, bazinga. Forget it.” style.
    2. Either I start dumping what I am reading to a file and work from this file once all data is read.

But then, what is the point? I can not find out the origin of the data that I am reading. If this is a local 8Gb file, I’ll be dumping it to another 8Gb file on the same system.

So, my question is :

How do you read efficiently a lot of data from an stdinpipe when you have to seek back and forth in it?

Thanks in advance for your answers.

Edit :

My program needs to read metadata somewhere (depending of the file format) in the given file, so that maybe at the end of the stream. Then it may read back other data at the start of the stream, then at another place etc. In short : it needs to have access to any bytes of the data.

An example would be to read data of an archive file without knowing the file format before starting to read from stdin: I need to check the archive metadata, find archive files names and offsets etc.

So I’ll make a local copy of stdin content and work from it. Thanks everyone for your inputs 😉

  • 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-03T06:54:39+00:00Added an answer on June 3, 2026 at 6:54 am

    The data structure in your 4GbDataFile just doesn’t lend itself to what you want to do. Think outside the box. Don’t hammer your program into something it shouldn’t even attempt. Try to fix the input format where it is generated so you don’t need to seek back 4 GB.

    In case you do like hammering: 4GB of in-core memory is pretty expensive. Instead, save the data read from stdin in a file, then open the file (or mmap it) and seek to your heart’s content.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I am currently running into a problem where an element is coming back from
I have some data like this: 1 2 3 4 5 9 2 6
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
Specifically, suppose I start with the string string =hello \'i am \' me And

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.