Что такое si_int в siginfo и как это влияет на распространение сигнала - PullRequest
2 голосов
/ 14 июня 2019

Как часть отправки прерываний в пространство пользователя, я вижу следующий фрагмент кода, но не понимаю, как si_int влияет на распространение сигнала.

static int SendToUsrSpace(void) {
  struct siginfo info;
  struct task_struct *t;
  int ret;

  memset(&info, 0, sizeof(struct siginfo));
  info.si_signo = 44;
  info.si_code = SI_QUEUE;
  info.si_int = 1234; // WHY NOT 36 or any random number?
  [...]
  ret = send_sig_info(44, &info, t);
  [...]
}

1 Ответ

1 голос
/ 14 июня 2019

Я думаю, что объяснение в sigqueue (3) .Из текста:

       sigqueue() sends the signal specified in sig to the process whose PID
       is given in pid.  The permissions required to send a signal are the
       same as for kill(2).  As with kill(2), the null signal (0) can be
       used to check if a process with a given PID exists.

       The value argument is used to specify an accompanying item of data
       (either an integer or a pointer value) to be sent with the signal,
       and has the following type:

           union sigval {
               int   sival_int;
               void *sival_ptr;
           };

       If the receiving process has installed a handler for this signal
       using the SA_SIGINFO flag to sigaction(2), then it can obtain this
       data via the si_value field of the siginfo_t structure passed as the
       second argument to the handler.  Furthermore, the si_code field of
       that structure will be set to SI_QUEUE.

Итак, 1234 выглядит как произвольное значение, которое процесс может извлечь (если у него есть обработчик для этого сигнала).Это похоже на способ отправки данных с сигналом.

Дополнительное чтение: я пришел к sigqueue из sigaction (2) , который выдает тип данных для siginfo_t.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...