C implementation of Linux command ps -ax
Developing Linux system call for ps -ax command.
Implemented ps -ax command in C (instead of system call) because of lack of proper information and books on kernel mode functions.
- Read about basic hello word system call on web and implemented as directed.
- Tried finding source code for ps-ax command, so that it can be modified to work in kernel mode. Source code available but without proper documentation, so hard to understand.
- Decided to write my own code, analysed output of ps-ax command, read the man page of ps, how ps is implemented, from where it takes input, what are outputs, significance of metrics and data in output, everything is available in man page of ps.
- ps read proc virtual file system and takes all the information about each process from this file system. Read the man page of proc, which describes what are the entities in the file system, how they can be used to know about the process completely.
- The whole program is written by just properly reading man pages of proc and ps mainly, without any sort of external help. All the variable names used are mentioned in man pages.
- Then tried running same program in kernel mode by adding it to kernel source code.
- Came to know that user mode function like printf, fopen etc, are not supported in kernel mode.
- Tried replacing each of user mode function with kernel mode function doing same task, but failed in doing so. (Reason mentioned above)
Somehow modify the code to support in kernel mode by finding appropriate functions or may be some other way.
- gcc compiler
- Linux environment
- C libraries used in code
gcc ps-ax.c
./a.out