Hi I am trying create a system call that will count the number of forks that were called. I was going to change the fork system call so that it has a counter that will keep track of the number of times fork() was invoked. I was planning on adding a static variable to fork.h and then increment that everytime fork.c is called. I just don’t understand what is going on in fork.c at all. Is this even the right approach?
Share
The Linux kernel already maintains a count of the total number of forks in the system as a whole.
One of the tasks performed by
copy_process(), which does a lot of the work involved in forking, is to increment thetotal_forkscounter.This counter is exposed to userland as the
processesline in/proc/stat(by the code here).