9.7. Kill a Child Process - kill_child

This function uses the Gamma exit_program function to terminate Gamma programs and the Gamma kill function to terminate non-Gamma programs.

   /*--------------------------------------------------------------------
    * Function:    kill_child
    * Returns:     t or nil
    * Description: Kills a child process.  We use exit_program() for Gamma
    *              programs, because that allows us to use atexit() within
    *              those programs to kill any of their children. The Cascade
    *              Historian must be flushed before it can exit.  The SIGCHLD
    *              handler does the cleanup for us.
    *------------------------------------------------------------------*/
   function kill_child(child, prog, process_name)
   {
     local retn, tsk;
     
     if (((prog == "gamma") || (prog == "phgamma")) && 
         ((tsk = locate_task(process_name, nil)) != nil))
       {
         send(tsk, #exit_program(5));
         close_task (tsk);
       }
     else

Since the History program automatically starts the Cascade Historian, we need to find it, flush the data from memory, and shut it down when History exits, using the Cascade Historian flush and exit commands.

       if ((process_name == "demohistdb") &&
           ((tsk = locate_task("demohistdb", nil)) != nil))
         {
           send_string(tsk, "(flush)");
           send_string(tsk, "(exit)");
           close_task (tsk);
           
           /*Give time to let child_died() send a message.*/
           usleep(10000);        
         }
       else
         kill(car(child), SIGINT);
   }