Home » Linux, OS Concepts and Networking » Operating System Concepts » Understanding filesystem presence for a simple C program when executing

Understanding filesystem presence for a simple C program when executing

In our last two posts, we tried to learn writing of a very minimal simple C program and how its its execution happens in real time. In this post, we will try to understand, when the program is actually executing, i.e. when program becomes a running process, what kind of files it creates in filesystem and information exported by the kernel related to this program.

Lets write a simple program creating a loop as additional to simple program we written in previous posts,

$ vim minimum-c-program.c
main() {
        while(1);
}

Above program just creates infinite loop using while(1) inside main, so that this program keeps on executing forever and not exits soon after executing.

$ gcc -o minimum-c-program_exe minimum-c-program.c

Now, lets execute this binary created using above program as,

$ ./minimum-c-program_exe

This above program will keep on executing due to while(1), so now we need to open another terminal and need to check what is the process id assigned to this running program,

$ ps -ax | grep minimum-c-program_exe
13027 pts/1    R+     0:05 ./minimum-c-program_exe

So this program is running as process id “13027” as seen above.

Every running process in Linux has one directory created in /proc with its process Id as directory name.

$ cd /proc/13027
$ ls
attr        comm             fd        map_files   net            personality  setgroups  syscall
autogroup   coredump_filter  fdinfo    maps        ns             projid_map   smaps      task
auxv        cpuset           gid_map   mem         oom_adj        root         stack      timers
cgroup      cwd              io        mountinfo   oom_score      sched        stat       uid_map
clear_refs  environ          limits    mounts      oom_score_adj  schedstat    statm      wchan
cmdline     exe              loginuid  mountstats  pagemap        sessionid    status

Now if we check the “cmdline” file contents using cat, it will show how we had started this program.

$ cat cmdline 
./minimum-c-program_exe

Subscribe our Rurban Life YouTube Channel.. "Rural Life, Urban LifeStyle"

Leave a Comment