Linux中的信号量错误 - :无效参数错误号:22(EINVAL)

时间:2015-11-09 09:40:04

标签: linux semaphore

我正在尝试在linux中执行一个C程序,我收到错误" P_Semaphore:无效的参数错误号:22,"可以有人帮忙

Int P_Semaphore(int i_sem_id)
{
 int i_code_returns;
 struct sembuf t_semop;
 #ifdef TRACE
 Debug(N_DEBUG_8, "P_Semaphore", "Entree, i_sem_id=%d<<<<<<\n", i_sem_id);
 #endif
 t_semop.sem_num = 0;
 t_semop.sem_op  = -1;
 t_semop.sem_flg = 0;
 do
 {
   i_code_retour = semop(i_sem_id, &t_semop, 0);

 } while ((i_code_returns == KO) && (errno == EINTR));

 if (i_code_retour == KO)
 {
   printf( "%s(%d):Error semaphore making attempt %d,errno = %d\n", M_HEADER, i_sem_id, errno);
  perror("P_Semaphore");
 }

1 个答案:

答案 0 :(得分:0)

根据semop手册(2)

   EINVAL The semaphore set doesn't exist, or semid is less than zero,
          or nsops has a nonpositive value.

因此,在您的情况下,nsops为零(非正数)。它应该是一个。

这是通话的第三个参数:

int semop(int semid, struct sembuf *sops, size_t nsops);