Skip to content

Instantly share code, notes, and snippets.

View bsce21017's full-sized avatar

Abubakar Saif bsce21017

  • Lahore, Pakistan
  • 10:18 (UTC +05:00)
View GitHub Profile
@bridgesign
bridgesign / getreadcount_system_call.md
Last active June 15, 2024 04:03
Creating a system call in xv6 for keeping count of read syscalls on per prcoess basis

Constructing a System call that gives the count of how many times System call Read was called.

We will be using xv6 OS for this exercise. In this exercise, we will construct a system call that can give read counts on per process basis and then modify it to obtain a system call that will give read counts of all processes since the start of kernel.

Adding the counter

To add a system call that can get the number of times the system call 'read' was used in a specific program, we require to make a variable that stores this count for each process.

So, we first start by looking at the files proc.c and proc.h
These files are associated with creating a process. We need to store the count on a per process basis so we will have to add something to the structure that is created for a process.
For that, open proc.h. In this file, the structure for a process is defined. Find struct proc and then add an integer to keep account for the read calls. eg. int readid;