Monday, September 9, 2013

How Linux stores Process Information


In Linux,whenever you run anything it runs as a process in Linux Operating System, so all of details are store in system, and it's very simple to get those information from this system. The point is to be consider here is how system store that information and where?. For example if you run C program and after that you have a.out object file that is generated by default in current directory. Okay after executing that a.out file, it also runs as process in system, for verification you can check it on terminal by using top command, top command will show you all information regarding a.out file, top will show process id, user name priority etc., as shown in figure.

Fig:-1

The next thing is how system maintain information of any process that in execution, after creation of process in Linux, System will create a directory of process with it's P_ID name. To check it, type ls /proc command on terminal, you can see that a directory is created with process_id of a.out in below figure. That directory has all information of a.out process. Here pgrep command is use to check the process id of a.out process.

Fig:-2

Now you can get all information of process(i.e. a.out process) from that directory which has same name as process id of process a.out. A directory 6114 has following files in it, it may happend that some of files may be missing.
Fig:-3

To check status of a.out process type cat /proc/PID/status. It will show all status information of a.out process as shown in figure.
Fig:-4

You can also check the maping information of your process by typing cat /proc/PID/smaps
Fig:-5

In this blog a just give a small example of how to get process information, you can do lots of thing with /proc directory.