Re: how does fork() work?

Snow Cat (snowcat@netgate.net)
Wed, 26 Feb 1997 09:44:34 -0800 (PST)


Marty Leisner once wrote:
>
>
> I want to write a debugging fork (i.e. one that prints and stops after forking).
>
> I want to use LD_PRELOAD to wrap around fork...so I need a more complicated C
> function called fork, eventually invoking the syscall.
>
> I'm a bit confused with the libc architecture for syscalls, what headers
> (sysdep?) do I need to pull out of the tree and place around an application
> for this?
>
> What I eventually want is:
>
>
> fork()
> {
> fancy stuff;
>
> result = system entry point fork()
>
> if(child) {
> printf();
> pause();
> }
> return result;
>
> }
>
>

The simpliest solution would be to call dlsym(RTLD_NEXT, "fork") (in <dlfcn.h>)
and link your preload library with -ldl. Free compatibility with Solaris :)

-- 
 _.    	        _       .  
(_ ,_  _ ,  .  / ` _ _L	 | Email: Oleg Kibirev <snowcat@netgate.net>
._)| U(_)\/\/  \_,(_L/L  | Visit http://math.math.CSUFresno.EDU/~oleg/math.html
------------------------'  to get my programs + PGP public key