fork/clone external to a process?
Hi,
Is there any clean way to fork a process from outside the process itself?
I'm running a commercial application that I only have a binary copy of. All the usual Posix fork stuff only works from inside the running process.
Is there any reason it's not possible to do so? Obviously threading and file desciptors open a whole can of worms, but in the base case, is it possible?
Thanks in advance, and sorry if it's a stupid question.
Dan Sturtevant
Quoted 7 lines · Dan Sturtevant
Hi,
Is there any clean way to fork a process from outside the process itself?
I'm running a commercial application that I only have a binary copy of. All the usual Posix fork stuff only works from inside the running process.
Have you tried playing with LD_PRELOAD (libc.so hack)?
Quoted 14 lines
Is there any reason it's not possible to do so? Obviously threading and file desciptors open a whole can of worms, but in the base case, is it possible?
Thanks in advance, and sorry if it's a stupid question.
Dan Sturtevant
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 10 lines
Quoted 7 lines
Hi,
Is there any clean way to fork a process from outside the process itself?
I'm running a commercial application that I only have a binary copy of. All the usual Posix fork stuff only works from inside the running process.
Have you tried playing with
LD_PRELOAD(libc.so hack)?
What I'm really looking to do is "checkpoint" the process. If I were inside the process, I'd fork off a child and call wait() in the parent. When I wanted to "revert" i'd kill off the child, which would return from the parent's wait(). I'm trying to do this to VMware. Because a forked child shares all the open file descriptors with its parent, they should be able to share the gui so long as only either the parent or child are awake at the same time.
I have allready modified the Bochs emulator and gotten it to do this, but I could just use fork the normal way inside the executable since it's an open source project.
(Yes, I know VMware allready has checkpoint/revert stuff and I don't need this crazy stuff to use it. I'm trying to do wierd stuff under VMware however.)
Ideally, i'd have some kind of wierd system call like:
childpid = wierd_external_fork(parentpid);
int wierd_external_fork(int parentpid)
{
int childpid;
wierd_sigstop_and_wait(parentpid);
childpid = wierd_copy_process_state(parentpid); //keep controling terminal? return childpid;
}
I think I understand what you're saying about using LD_PRELOAD to hijack a function call in a shared object. I could do this and try to slip a call to fork() into the executable by substituting a function and thus do this the normal way.
My problem is that I want this to happen on demand rather than whenever the substituted shared library call is invoked inside the executable.
I haven't messed around with LD_PRELOAD before. Am I interpreting everything correctly here or am I way off base?
Feel free to tell me that I'm smoking crack.
Thanks for the help.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 4 lines · Pjotr Kourzanov
What exactly are you referring to by "checkpoint" and "revert"? Do
you mean temporarily stop and then resume?
Checkpoint is a terrible name for what I want to do to the process. The only thing I mean is that I want one of the "forked" processes either wait() ing for the other one to end or SIGSTOPed so I can wake it up when the other ends. The sleeping one will be in the state that the other was in at the time of the fork.
Quoted 5 lines
Well, the kernel AFAIK makes deep copies of task structs only on
behalf of a process (would be a security hole otherwise). I suppose you could change that, but I am afraid there will be a lot of resistance to it on LKML...
I would never suggest anyone else do this to a kernel they care deeply about.
Quoted 10 lines
Quoted 5 lines
My problem is that I want this to happen on demand rather than whenever the substituted shared library call is invoked inside the executable.
Do you really need /that/ flexibility? Just strace vmware and see
what calls it does and when. Then just pick one that's in libc.so or another shared library. Don't forget to pass the call down to the original function;-)
I guess LD_PRELOAD could work. It would be especially nice if I could get inside a signal handler.
Thanks Pjotr
Hi!
Quoted 6 lines
My problem is that I want this to happen on demand rather than whenever the substituted shared library call is invoked inside the executable.
I haven't messed around with
LD_PRELOADbefore. Am I interpreting everything correctly here or am I way off base?
gdb attach the vmware, then force it to call routine you preloaded...
Or look at subterfugue.
Pavel
Signature · 2 lines
People were complaining that M$ turns users into beta-testers... ...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
Quoted 4 lines
gdb attach the vmware, then force it to call routine you preloaded...
Or look at subterfugue.
Pavel
Brilliant Pavel. Thank you. gdb works great.
Dan