fork and synchronous error problem



resending since no response yet:

fork and async problem

Currently I am working on an application which uses CLIST type list and
after the user selectes the t items they want from the list, they push a
button called 'start tasks' which starts the processes they have chosen
from the list.   Once they hit the start tasks button there is a callback
to the following function (some hopefully extraneous code left out for
simplicity):

The tasks that are strarted by the user are read in from a text file and
displayed in the list.  Each task is stored in a record and there is an
array of records called
'all_tasks' seen below.  The actual problem is that once the 'start tasks'
button is pushed, I get an unexpected async reply.  I am not using exit()
so this is not directly answered in the FAQ.

void start_tasks(GtkWidget *button, gpointer display_tasks)
{
  /* declare variables */
  char executable[100];
  char socket[7];
  pid_t pid;

  all_tasks=gtk_object_get_data(GTK_OBJECT(display_tasks),"task_list");
  printf(" length of list: %d \n",length);

  /* loop through all in list  */
  for(count = 0; count < length; count++)
  {
    exe_status = TRUE:
    /* get selected rows and use as an index in array of possible tasks to
start */
    row = (int)g_list_nth_data(GTK_CLIST(display_tasks)->selection,count);
    printf("row: %d \n",row);
    printf("directory path: %s \n",all_tasks[row].dir_path);

    strcpy(executable,all_tasks[row].dir_path);
    strcat(executable,"/");
    strcat(executable,all_tasks[row].executable);
    /* convert number parameters to character strings */
    sprintf(socket,"%d",all_tasks[row].sock);

    if ((pid = fork()) < 0)
      perror("fork error");
    else if(pid == 0)
    {
      if
(execle(executable,all_tasks[row].executable,all_tasks[row].ip_addr,all_
tasks[row].udp_port,
                    all_tasks[row].tcp_port,socket, (char *) 0, env_init) < 
0)
      {
        perror("execle error");
        printf("error starting task: %s \n",all_tasks[row].executable);
        exe_status = FALSE;
     }
   }
   /*  save the pid for the started process.  */
   if ((pid !=0)&&(exe_status !=FALSE)
   {
     printf("new proces id: %d \n",pid);
     all_tasks[row].process_id = pid;
   }
  }  /* end for */
}

The above routine is a callback from a start task button push after the
user has selected some tasks from the list.  The problem is then when
pushed I eventually get an unexpected async reply  - am I using fork wrong
to initiate these processes?  Am I being clear that I want to start any
number of executables read in from a text file or not?





[Date Prev <msg00062.html>][Date Next <msg00061.html>] [Thread Prev 
<msg00068.html>][Thread Next <msg00062.html>] [Thread Index <thread.html>] 
[Date Index <date.html>] [Author Index <author.html>]





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