سؤال

أنا أعمل على قذيفة يونكس ، باستخدام لغة سي.يمكنني استخدام ويتبيد لانتظار العمليات الخاصة بي لإنهاء وأريد أن أعرف ما إذا كانت عملية ابني (التي تم إنشاؤها باستخدام fork() ) تلقى إشارة مثل SIGSEGV.

الرمز الحالي :

static const t_error    error[ERROR_NBR]= {
  {SIGHUP, "Hangup"},
  {SIGQUIT, "Quit (core dumped)"},
  {SIGABRT, "Abort (core dumped)"},
  {SIGBUS, "Bus error (core dumped)"},
  {SIGFPE, "Floating exception (core dumped)"},
  {SIGKILL, "Killed"},
  {SIGUSR1, "User signal 1"},
  {SIGSEGV, "Segmentation fault (core dumped)"},
  {SIGUSR2, "User signal 2"},
  {SIGPIPE, "Broken pipe"},
  {SIGTERM, "Terminated"},
};

void print_signal_message(int status)
{
 int i;
 if (WIFSIGNALED(status))
    status = WTERMSIG(status);
 else
    return ;
 i = -1;
 while (++i < ERROR_NBR)
   {
     if (status == error[i].error_status)
       {
         fprintf(stderr, "%s\n", error[i].error);
         return ;
       }
   }
 return ;
}
int             xwaitpid(int pid, int *status, int opt)
{
  int           ret;

  ret = waitpid(pid, status, opt);
  if (ret == -1)
    fprintf(stderr, "Can't perfom waitpid (pid = %d)\n", pid);
  if (WIFEXITED(*status))
    *status = WEXITSTATUS(*status);
  else
    **print_sigerr(*status);**
  return (ret == -1 ? (1) : ret);
}

xwaitpid يسمى في العملية الأم.

يبدو أن ويفسنيلد يعود دائما صحيح ، حتى عندما تنفيذ أمر مثل false || true.

شخص ما لديه فكرة جيدة يمكن أن تساعدني ?

- >وجدت جوابي ، وذلك بفضل.

هل كانت مفيدة؟

المحلول

if (WIFEXITED(*status))
    *status = WEXITSTATUS(*status);

هذه مشكلتك.لا يمكنك WIFSIGNALED على *status بعد ذلك ، فقدت البتات المطلوبة في ذلك int.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top