Attach my own pid
Nitin Varyani
varyani.nitin1 at gmail.com
Sun Mar 27 07:27:54 EDT 2016
If I do the following thing:
struct pid remote_struct_pid;
remote_struct_pid.numbers[0].nr=*my_pid*;
p = copy_process(clone_flags, stack_start, stack_size, child_tidptr,
*remote_struct_pid*, trace, tls);
and modify the copy_process function little bit (marked in BOLD), it may
serve my objective.
if (pid != &init_struct_pid *&& pid == NULL*) {
retval = -ENOMEM;
pid = alloc_pid(p->nsproxy->pid_ns);
if (!pid)
goto bad_fork_cleanup_io;
}
p->pid = pid_nr(pid);
The pids by kernel are allocated in the range (RESERVED_PIDS,
PID_MAX_DEFAULT) and I will choose *my_pid* outside this range.
I will have to modify system calls/kernel to cater to such processes.
On Tue, Mar 22, 2016 at 3:55 PM, Bernd Petrovitsch <
bernd at petrovitsch.priv.at> wrote:
> On Die, 2016-03-22 at 01:26 -0400, Valdis.Kletnieks at vt.edu wrote:
> > On Mon, 21 Mar 2016 16:01:41 +0530, Nitin Varyani said:
> >
> > > I am running a master user-level process at Computer 1 which sends a
> > > process context like code, data, registers, PC, etc as well as *"pid"*
> to
> > > slave processes running at other computers. The responsibility of the
> slave
> > > process is to fork a new process on order of master process and attach
> *"pid"
> > > *given by the master to the new process it has forked. Any system call
> on
> > > slave nodes will have an initial check of " Whether the process
> belongs to
> > > local node or to the master node?". That is, if kernel at Computer 2
> pid of
> > > the process is 1500
> >
> > None of that requires actually controlling the PID of the child.
>
> Well, I think that the OP wants to map the PIDs with a fixed offset per
> host. So e.g. the local PID == 14 becomes 20014 on all other nodes.
> At least for debugging it's easier than some random mappings;-)
>
> As for top post: TTBOMK there is no SysCall for doing that.
> * Perhaps one can achieve something similar with containers - one
> container per remote host or so (but I never used containers actively
> myself) or (ab)use KVM (does vServer still live?) for local
> "pseudo-VMs" (and use there the original PIDs - or so).
> * The manual page of clone(2) doesn't reveal to me if it's possible to
> wish for a PID.
> * You could clone (pun not intended;-) the fork() syscall and add an
> parameter - the PID - to it (and e.g. return -1 if it's already used).
>
> BTW I don't know how the rest of the kernel reacts to such artifical
> PIDs (but you will see;-) outside the "official range".
>
> MfG,
> Bernd
> --
> "What happens when you read some doc and either it doesn't answer your
> question or is demonstrably wrong? In Linux, you say "Linux sucks" and
> go read the code. In Windows/Oracle/etc you say "Windows sucks" and
> start banging your head against the wall." - Denis Vlasenko on lkml
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20160327/30b05932/attachment.html
More information about the Kernelnewbies
mailing list