Help with processes questions

Please help this uses C in conjunction with C++ I am not familiar with how to go about these prompts:

Use the ps, ps -lx, pstree and ps -aux commands to display the information about process attributes.

Use the top command to display the resource utilization statistics of processes.

Open a terminal and type the top command.
Start a browser and see the effect on the top display.
Compile a C program and observe the same effect.

From the top display, answer the following:
How much memory is free in the system?
Which process is taking more CPU?
Which process has got maximum memory share?

Answer the following questions:
What is the output of pstree (description)?
What is the output of ps -aux (description)?

Execute a CPU bound program
Describe the effect of their CPU share using the top display and comment.
Execute an I/O bound program
Describe the effect of their CPU share using the top display and comment.

Please help me explain the answers to these questions. This is not a test or an assignment, its part of an ongoing laboratory but kind of left to learn for myself here.
its more about the linux ps command than anything in c/c++

i mean it wants you to run a program or two, so you can see the numbers from PS change, is all it wants.

do you understand a cpu bound program? Just do something like while(true) compute something... call your own babylonian sqrt or something.. right? Keep it short and simple or just steal code online.

This has nothing to do with C or C++. It is all about observing the processes running on your system by using commands at the terminal.

The first thing you should do is start learning about those commands. An easy way to get somewhere is also to simply run them as indicated. For example, start your linux terminal and when you see % type:

  ps -lx

and press Enter. The processes command (ps) will list all running processes and give you information about them. To learn more about the ps command, type:

  man ps

or simply Google it.

The part to compile a C program is simply to see it in the process tree. Any program will do. Here's one:

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

int main()
  char name[100] = { '\0' };

  printf( "What is your name? " );
  fflush( stdout );

  if (fgets( name, 100, stdin ))
    char* p = strchr( name, '\n' );
    if (p) *p = '\0';
  if (strlen( name ) == 0)
    strcpy( name, "world" );

  printf( "Hello %s!\n", name );
  return 0;

Compile it with

  gcc hello.c

and run it with


If you want to see the effects of the program while it is running, press Ctrl+Z to move it to the background and run the ps command. Type

  fg 1

to move it back to the foreground (so that you can terminate it properly).

Good luck!

[edit] Sorry, been a while since I wrote anything in C. Fixed my error.
Last edited on
Registered users can post here. Sign in or register to post.