X-Winodw - Process runs after killing the winodw

I have a problem, I use glx to create the window and uses a while loop to draw the picture. But, after killing the Xwinodw, the process is still running, is there any call backs for knowing the status of the winodw (whether it is killed or not)?

the code
int main()
{
init_glxWindow();

while(1)
{
//someglxcalls;
glXMakeCurrent(display, window, context);
glXSwapBUffers(display,window);
glxWaitVideoSyncSGI(4,0, &i);
glFlush();
draw_picture();
}
return 0;

}
Is there any way I can get the status of the winodw, and then I can use that instead of while(1). Please help me
thanks,
nt