Problems using raypcalls

Hi,

I’m trying to use the raypcalls library, and for some reason the child processed never seem to exit, even after they (supposedly) finish their work. Calling ray_pclose just causes the execution to wait forever.

Upon investigating further, it seems that calling exit() from the sub-process has no effect. Using _exit() on the other hand does work.

Any ideas on what may cause this?

Thanks

Yes, the quit() routine defined in the subprocess needs to follow what we do in rtrace.c, which is call _exit() if ray_pnprocs < 0. While it is improper to call exit() in a subprocess, since it can flush output files multiple times, it should not cause the process to hang. I don’t really know why that is happening in your case.

Thanks for your reply, Greg.

Looking at quit() function in rtrace.c I see it’s actually calling regular exit() and not _exit(), so I’m a bit confused:

void quit( /* quit program */ int code ) { if (ray_pnprocs > 0) /* close children if any */ ray_pclose(0); #ifndef NON_POSIX else if (!ray_pnprocs) { headclean(); /* delete header file */ pfclean(); /* clean up persist files */ } #endif exit(code); }

In fact the only reason I used exit() is because I followed this function. I have no problem using _exit() instead, but I was concerned I might get myself into trouble.

Thanks in advance

Not sure which version of rtrace.c you are looking at, but the latest is here, which has:

void
quit(			/* quit program */
	int  code
)
{
	if (ray_pnprocs > 0)	/* close children if any */
		ray_pclose(0);		
	else if (ray_pnprocs < 0)
		_exit(code);	/* avoid flush() in child */
#ifndef  NON_POSIX
	else {
		headclean();	/* delete header file */
		pfclean();	/* clean up persist files */
	}
#endif
	exit(code);
}

There was a change last summer that added this new line. However, the one before then did not have trouble exiting. As I said, I would not expect calling exit() to stall.

Thanks Greg, looks like I’m a bit behind.

The call to exit() didn’t stall, it’s just didn’t do anything at all, causing the process to return to ray_pchild (which should never happen). In any even I’ll try working with _exit().

One more question on the same topic:

ray_pchild calls quit(), which internally calls _exit.
However in the make file I see that rtrace is also linked to rtrad which also has quit.c with another function called quit(), so I’m a but confused. How does this even compile?

Thanks

That’s really non-standard behavior. The whole idea of exit() is never to return, so I’m flummoxed why it would “do nothing,” implying it returns.

Regarding the quit.o module included in librtrad.a, libraries only pull in modules “as needed,” meaning symbols not defined in the linked program or previous libraries on compiler/linker command line. You can redefine most library functions to your liking, which is a bit dangerous if you aren’t careful!

Well, one important detail might be that I’m calling it from within a MEX function (Matlab C++ library). I have no idea why that would make a difference though.

Unless the Matlab C++ library replaced exit() with their own call, which sometimes returns. (See previous post!)