The source code for fork can be found in the <linux kernel source tree>/kernel/fork.c file. do_fork function. You can add your code right before the else , which returns errors. Remember that you will need to compile and reboot this new kernel.
source share