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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:54:11+00:00 2026-05-25T06:54:11+00:00

So, this seemed simple at first, but after crawling Google and here, the answer

  • 0

So, this seemed simple at first, but after crawling Google and here, the answer doesn’t seem as simple as I first thought.

Basically, I’m editing a MINIX kernel as part of a practical for my Operating Systems course, and I have to add a little function that spits out the number of running processes when you hit a function key in the Information Server. I’ve figured out how to integrate the functionality so all the other stuff works, but for the life of me, I can not figure out how to get the current number of processes running in the system into my C code and into a variable to print out.

First I thought there’d be a nifty Syscall like SYS_NUMPROCS or something that’d return the value, but no luck.
Then, I tried piping output from a system(“ps -ax | wc -l”) to a file and the file wouldn’t create. I tried using popen() and no luck there either – even with a simple “ls” read into a buffer, it just bombs the code and “hangs” the run of the code, so there’s no output.

So now I’m truly stumped, and any help would be super awesome, because at this point I’ve exhausted all the obvious options.

The only two things I can think of now would be a loop counting all the processes, but first you have to get to the system’s process list, and I’ve heard vague things said about /proc/ as a directory, but I haven’t a clue how to access/run through that or how it’d link up to getting the number of processes in the first place.

Thanks a stack (lol pun), guys 🙂

Also, I haven’t included code explicitly because nothing I’ve written aside from basic printf’ing for cosmetic output, because none of the things I’ve tried gave me any joy :/

Edit notes: Guys, this is a kernel edit – I’m writing the function to printf the information in a system C file, then recompiling the kernel and rebooting the system to test. It’s a UNIX (MINIX) kernel, not a Linux kernel, and it’s not a user mode program.

My code for popen(), as some of you requested, is as follows:

public void cos_dmp(){
    char buffer[512];
    FILE * f;

    f = popen("ps -ax | wc -l","r");

    fgets(buffer, sizeof(buffer),f);

  //buffer should now contain result of popen()

     printf(buffer);
}

That’s a bit of a hacked together version from what I remember and keeping it ultra simple and showing you guys that’s what I was trying to do. Again though, there must be a better way to do this aside from essentially calling the output of a system() call.

Edit again: the above code woks perfectly from a user program but won’t work from the kernel function. Anybody have an 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-25T06:54:11+00:00Added an answer on May 25, 2026 at 6:54 am
    struct kinfo kinfo;
    int nr_tasks, nr_procs;
    getsysinfo(PM_PROC_NR, SI_KINFO, &kinfo);
    nr_procs = kinfo.nr_pro;
    

    This will get you the number of processes running

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

Sidebar

Related Questions

This one has me puzzled. It seemed like an easy task, but the solution
This might seem like a stupid question I admit. But I'm in a small
This is a difficult and open-ended question I know, but I thought I'd throw
This is my first post here and I wanted to get some input from
I'm hoping this is a rather simple question, but I'm pretty new to MVC
This seemed like an easy thing to do. I just wanted to pop up
This is a bit of a long shot, but if anyone can figure it
This is kinda oddball, but I was poking around with the GNU assembler today
I don't know if this is the place to ask about algorithms. But let's
I've been trying to debug this problem for many hours, but to no avail.

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.