I was taught in school that this was impossible. That's apparently no longer true, but it's fairly involved to get around it for a single process.
The two links given to you in comments explain what easy options you have to accomplish what you are wanting to accomplish. However, they either require you to take action before you start the command you want to move
https://unix.stackexchange.com/a/8696/329452
https://unix.stackexchange.com/a/49155/329452
or they only tell you how to change the tty the process is using (so you can move the input and output, but it's not going to be the child of the active process)
https://unix.stackexchange.com/a/4035/329452
There's a lot more answers on those posts, but they're basically duplicates of these.
In order to change the parent of a process, its parent has to die. Back in the day, that would always change the parent to PID 1. I'm not sure when this changed, but since Linux 3.4, the process that acquires all of the orphans can be changed: https://unix.stackexchange.com/a/177361/5132. I'm still looking over the results of that. I would have thought that significant of a change would have enabled systemd to not be nearly so monolithic - but apparently, systemd is monolithic for its own sake. (roughly 90% of the way down on that page)
That having been said, the process that takes on this role has to take on the entire role. It's not just something to do for one process.
Most unix shells do not have any code in them to allow them to recognize a new child that was just grafted in. Some of them are more amenable than others to getting notified of such children ending. I'd expect adding those processes to job control would not be a common shell feature. I think zsh's modules would be able to add support to the shell if that was desired. I haven't actually looked for zsh modules that aren't part of the zsh package that do this yet, nor have I looked for other shells that can handle it yet.
setns(a_name_space,CLONE_NEWPID);fork();
into a process. Wherea_name_space
is a name space owned by a shell (running as process 1). If it works (and does not cause its own problems), then the process will become child of the shell, and now just to solve the other problems. – ctrl-alt-delor Feb 16 '19 at 12:11