Re: [gtkmm] BadWindow ( invalid Window parameter ) / Gtk::Dialog hell for newbie



On Friday 16 April 2004 18:25, Akbar wrote:


> I am newbie so I don't fully understand this statement. But I finnaly
> found the bug.....
> Consider this code:
>
> int medium_calling_fork() {
> 	pid_t child;
> 	child = fork();
> 	if(child==0) {
> 	     for( int i=0; i<files.size(); i++ ) {
> 	        	song = Direct + "/" + files[i];
> 	        	on_processing();
> 	     }
>
>
>
>              // Without this statements, my program will be error
> 	     char *arg[] = {
> 		     "ls",
> 		     NULL
> 	     };
> 	     execvp("ls",arg);
>              //End of comment
>
>
>
>         }
> 	else return child;
> }
> So I need to make my child process encounter this statement: execvp() no
> matter what happens. Can you explain this to me???? Any better idea?

This has nothing to do with GTK+/gtkmm, and I do not know if you have by now 
worked out by yourself how to resolve this, but the point is that the new 
process you create with fork() will continue executing through your code 
until you terminate it, or you call one of the exec() family of functions 
(the execvp() call will replace the fork()ed process image with a new process 
image executing the program called by execvp(), and if successful will not 
return).  What you should do in your case is to terminate the child process 
at the appropriate point (where you called execvp() - in effect at the end of 
your (if child == 0) block) with a call to _exit() (Unix _exit() with a 
prepended '_' and NOT Ansi C exit()).  In the absence of this, in your 
example both processes would return from medium_process_fork() and continue 
executing the function which called it.

In fact you should always call _exit() after an exec() call, as the exec() 
call can fail, say if the program to be executed can't be found, and return 
(if it succeeds it never returns as mentioned above).  You can insert an 
appropriate error message between the exec() and _exit() calls notifying the 
user that the exec() call has failed.

The best thing for you to do is to read up about the Unix system calls.  
fork() does take a bit of getting used to if you have not used it before.

Anything further should dealt with off the mailing list.

Chris.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]