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

Failure to kill pid




The code below creates a fork to run grep.
Code works correctly except for KILL resulting in an inability
to reuse a grep file search.  The question is why the PID goes Zombie vs
being killed. Replace the PID with 0 and parent is killed as expected.
Suggestions ?


	a0 = "grep"; // Fixed
	a1 = "-n"; // Switches Built Up
	a2 = entry_text; // From entry
	a3 = "/home/john/proj/Syntax/src/callbacks.c"; // File Data
	socket = "/tmp/se";
	if (a0 != NULL && a1 != NULL && socket != NULL)
	{
		gchar *argv[4] = { a0,a1,a2,a3 };
		result = g_exec( argv, socket );
	}


gint g_exec( gchar **argv, gchar *socket )

{
	gint pid;
	gint ret;
	gint flags = O_WRONLY | O_CREAT | O_TRUNC ;
	gint mode =  S_IRWXU  | S_IRWXG | S_IRWXO;
	TASK_WORKING = TRUE;
	
	signal( SIGCHLD, sigchld_handler);

	pid = fork();

	TASK_PID = pid;

	if( pid < 0 )
	{
		fprintf(stdout,"Fork Failed: %d",-1);
		return -1;
	}

	if( pid > 0 )
	{
		fprintf(stdout,"Fork successfull: %d\n",pid);
		return pid;
	}
	else
	{
	   // Child process
		/* open socket */
		TASK_HANDLE = open( socket, flags, mode );
		/* redirect output and input */
		close (0); dup (TASK_HANDLE);  /* set the stdin to the in pipe */
		close (1); dup (TASK_HANDLE);  /* set the stdout to the out pipe */
		close (2); dup (TASK_HANDLE);  /* set the stderr to the out pipe */
		/* execute program */
		TASK_PID = execvp( argv[0], argv );
		if( ret < 0 )
		{
			fprintf(stdout,"execvp: error unkown!\n");
			perror( "execvp" );
			return -1;
		}
		
		return 0;
	}	
}

void sigchld_handler (gint signal)
{
	close (TASK_HANDLE);
	kill (TASK_PID,9);
	TASK_WORKING = FALSE;
}

--
 \!!!/            
 ($$) 
_(_)_Ooo__________________________________
_____!_____!_____!_____!_____!_____!_____!___!
___!____!_____!_____!_____!_____!_____!_____!_
___!____!_____!_____!_____!_____!_____!_____!_
  "The grass is a little greener over here!"

Have a nice day! :-)

John Hawk
Email: john.hawk@gte.net
"Got-Ya! it was sea-grass. I'm a diver hope you are!"



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