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?
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 the total_forks
counter .
This counter is exposed to userland as the processes
line in /proc/stat
(by the code here ).
The source code for fork
can be found at <linux kernel source tree>/kernel/fork.c
file. The function is do_fork
. You can add your code right before the else
statement which returns errors. Remember that you would have to compile and reboot with this new kernel.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.