I was referring: http://www-users.cs.umn.edu/~boutcher/kprobes/kprobes.txt.html to understand kprobe. I used kprobe_example.c as given in the doc.
I compiled it using the makefile (code taken from the same document)
I got compilation errors because my kernel version is 4.2 and some fields were changed in struct pt_regs. So I replaced eip with ip and eflag with flag in kprobe_example.c which is https://gist.github.com/murlee417/87c2eb43a6afa1954b05404a07813e81. Then I was able to compile it successfully.
Now, as a root user, I did:
#insmod kprobe_example.ko
and I got:
insmod: ERROR: could not insert module kprobe_example.ko: Operation not permitted
My message buffer has:
#dmesg
[ 4537.478408] Couldn't find do_fork to plant kprobe
Please help me to resolve this error and make insmod work.