IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 13, 2005, 10:30:13 AM (21 years ago)
Author:
eugene
Message:

working on speed issues

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/pclient/reset.c

    r4689 r4762  
    44
    55  int i, result, waitstatus;
     6  struct timespec request, remain;
    67
    78  if (argc != 1) {
    89    fprintf (stderr, "USAGE: reset\n");
    9     fprintf (stdout, "STATUS -1\n");
     10    fprintf (GetOutfile(), "STATUS -1\n");
    1011    return (FALSE);
    1112  }
     
    1314  if (ChildStatus == PCLIENT_NONE) {
    1415    fprintf (stderr, "no child process, cannot reset\n");
    15     fprintf (stdout, "STATUS 2\n");
     16    fprintf (GetOutfile(), "STATUS 2\n");
    1617    return (TRUE);
    1718  }
    1819
     20  /* avoid blocking on waitpid, test every 100 usec, up to 50 msec */
     21  request.tv_sec = 0;
     22  request.tv_nsec = 100000;
     23
    1924  if (ChildStatus == PCLIENT_BUSY) {
    20     /* send SIGTERM signal to job */
     25    /* job is still running, send SIGTERM signal to job */
    2126    kill (ChildPID, SIGTERM);
    22     result = 0;
    23     for (i = 0; (i < 10) && (result == 0); i++) {
    24       usleep (10000);  /* 10 ms is min */
     27    result = waitpid (ChildPID, &waitstatus, WNOHANG);
     28    for (i = 0; (i < 500) && (result == 0); i++) {
     29      nanosleep (&request, &remain);
    2530      result = waitpid (ChildPID, &waitstatus, WNOHANG);
    2631    }
    2732    if (result) goto reset_job;
    2833
    29     /* send SIGTERM signal to job */
     34    /* job did not exit, send SIGKILL signal to job */
    3035    kill (ChildPID, SIGKILL);
    31     result = 0;
    32     for (i = 0; (i < 10) && (result == 0); i++) {
    33       usleep (10000);  /* 10 ms is min */
     36    result = waitpid (ChildPID, &waitstatus, WNOHANG);
     37    for (i = 0; (i < 500) && (result == 0); i++) {
     38      nanosleep (&request, &remain);
    3439      result = waitpid (ChildPID, &waitstatus, WNOHANG);
    3540    }
     
    3843    /* total failure, don't reset */
    3944    fprintf (stderr, "child process %d is hung, cannot reset\n", ChildPID);
    40     fprintf (stdout, "STATUS 0\n");
     45    fprintf (GetOutfile(), "STATUS 0\n");
    4146    return (FALSE);
    4247  }
     
    5762  ChildExitStatus = 0;
    5863
    59   fprintf (stdout, "STATUS 1\n");
     64  fprintf (GetOutfile(), "STATUS 1\n");
    6065  return (TRUE);
    6166}
     
    6873*/
    6974
     75/* the linux kernel timer sticks in a 10ms lag between kill and the harvest */
Note: See TracChangeset for help on using the changeset viewer.