Getting System and Process Information Using C Programming and Shell in Linux
Whenever you start a new process in Linux it creates a file in /proc/ folder with the same name as that of the process id of the process. In that folder, there is a file named “status” which has all the details of the process. We can get those Process Information Through shell as follows:
cat /proc/1/status

As can be seen, it displays most of the information about the process.
Note:, In this case, the process id is 1, it may be changed as per need.
You can get the System Information through the shell. The basic system information is stored in a file named os-release in /etc/ folder.
cat /etc/os-release

You can also get the System Information using C programming. The below code is used to get the details of the system. In this code, utsname maintains a structure that has the details of the system like sysname nodename, release, version, etc.
#include<stdio.h> #include<stdlib.h> #include<errno.h> #include<sys/utsname.h> int main() { struct utsname buf1; errno =0; if(uname(&buf1;)!=0) { perror("uname doesn't return 0, so there is an error"); exit(EXIT_FAILURE); } printf("System Name = %s\n", buf1.sysname); printf("Node Name = %s\n", buf1.nodename); printf("Version = %s\n", buf1.version); printf("Release = %s\n", buf1.release); printf("Machine = %s\n", buf1.machine); } |
On execution the above code will give the following output:

To get Process Information using C programming, use the below code. In this code, we execute the Linux command through a c program to get the details of the process.
#include<stdio.h> #include<stdlib.h> int main() { int r=system("cat /proc/1/status"); } |
On execution the above code will give the following output:

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
Recommended Posts:
- Introduction to Linux Shell and Shell Scripting
- How to Install Z Shell(zsh) on Linux?
- Making your own Linux Shell in C
- A Shell program To Find The GCD | Linux
- Basic Shell Commands in Linux
- Developing a Linux based shell
- How to find time taken by a command/program on Linux Shell?
- Reverse a String | Shell Programming
- How to check if a directory or a file exists in system or not using Shell Scripting?
- Process Management in Linux
- Priority of process in Linux | nice value
- Exit status of a child process in Linux
- What is Linux System Administration?
- Maximum number of Zombie process a system can handle
- proc file system in Linux
- Users in Linux System Administration
- Groups in Linux System Administration
- Introduction to Linux Operating System
- dup() and dup2() Linux system call
- SAR command in Linux to monitor system performance
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

