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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:12:42+00:00 2026-05-28T13:12:42+00:00

I have been able to write a program that can read any text files…

  • 0

I have been able to write a program that can read any text files… except the ones found in /proc. Any file that I try to read from /proc shows up empty.

But whenever I type

cat /proc/cpuinfo

on terminal, I am presented with my CPU info.

I can also see the file when I open it with a text editor, such as gedit or leafpad.

So it seems that /proc files are indeed text files, but my C program is having a hard time reading them.

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

char* readFileString( char* loc ) {
        char *fileDat;
        FILE * pFile;
        long lsize;

        pFile = fopen( loc, "r" );

        // Grab the file size.
        fseek(pFile, 0L, SEEK_END);
        lsize = ftell( pFile );
        fseek(pFile, 0L, SEEK_SET);

        fileDat = calloc( lsize + 1, sizeof(char) );

        fread( fileDat, 1, lsize, pFile );

        return fileDat;
}

int main( void ) {
        char *cpuInfo;

        cpuInfo = readFileString( "/proc/cpuinfo" );

        printf( "%s\n", cpuInfo );

        return 0;
}

Any idea why?

  • 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-28T13:12:43+00:00Added an answer on May 28, 2026 at 1:12 pm

    The files from /proc have a size of 0 byte because they are generated on the fly by the kernel.

    See here for more information on proc filesystem:

    http://tldp.org/LDP/Linux-Filesystem-Hierarchy/html/proc.html

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

Sidebar

Related Questions

I need to write a simple terminal-based program that should, Read some text from
I have been able to design my layout so that it has 2 columns
The best that I have been able to come up with is: strlen(preg_replace('/^([\\*]*)\s(.+)/',$1,$line)); ^^That
It seems obvious that some people have been able to figure out how to
I've been trying to write a program in R that implements Newton's method. I've
I have two (UNIX) programs A and B that read and write from stdin/stdout.
I have been asked to write a (very) simple program for a set of
I have been able to zip the contents of my folder. But I would
I have been able to copy the raw data from an otherwise inaccessible USB
I have been able to create ASPX pages without the code behind, but 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.