Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the Fork() system call

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?

like image 631
ddd Avatar asked Feb 09 '11 23:02

ddd


1 Answers

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).

like image 89
Matthew Slattery Avatar answered Oct 05 '22 11:10

Matthew Slattery