I have recently started reading some documentation on brk()
and sbrk()
, and I understand that the entire point of these system calls is to modify the program break, which points to the top of the heap segment for a process.
But how does the kernel know where to find the program break value for a process? Can it be found within the process table or does a specific CPU register hold this value?
I looked into Intel’s x86-64 and could not find any details on the program break that would suggest to me that its stored in a CPU register. Furthermore, I cannot seem to figure out how I can view the process table.
2
This value is definitely not stored in a register. That would be extremely wasteful. Registers are extremely limited and not used for this kind of rarely-used values.
“The process table” is a shorthand to describe all kinds of data that belong to a process. For instance, “the process table” contains information about all threads of a program, but that obviously isn’t a fixed-length array. Many programs have only one thread, others have thousands. Some things are only dynamically allocated when needed.
As brk
is entirely outdated (it was removed from POSIX two decades ago), the value might not even exist until an old-fashioned program runs and calls brk
or sbrk
.
See also What’s unsafe/legacy about brk/sbrk?
2