I know this can be done in the user space and this has been answered before.
However, I would like to be able to do it from with a kernel function/module.
UPDATE
The c code (referred to from the other answered question) is part of the criu project. And the file /proc/sys/kernel/ns_last_pid
does not exist in all systems. So, the code does not work on ubuntu. Is there any way I can make it work on ubuntu?
My final goal is: fork a process and give it the ID of the parent.
Steps: staring with a process names P with id x.
- Fork a process from within P. Name the child Q.
- Assign the parent process P a temp id, say a.
- Change the id of the child process Q and set it to be x.
- Another kernel function will rewire the parenthood of child process Q. So that parent of P becomes parent of Q. In other words, the child process will take the identity of its parent.
- Process P dies off since it is not waiting on any process.
I know how to do the steps 4-5. I have already implemented that. I am hacking another Linux kernel project. So, I have no other way around this. I have to implement this way.
Thanks all.