Error On Semop Invalid Argument
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Semop: Invalid argument up vote 1 down vote favorite I have this code that basically makes a P on the semaphore with number sem. The semaphore is in a pool. The problem is that sometimes I get Invalid argument and I can't figure out why. bool sem_p(key_t key, int sem){ int semid = semget(key, sem, 0666); struct sembuf sb = {sem, -1, 0}; if(semop(semid, &sb, 1) == -1){ perror("sem p"); printf("sem %d\n", sem); return FALSE; } return TRUE; } When that function gets called, it prints sem p: Invalid argument c semaphore invalid-argument share|improve this question asked Feb 3 '14 at 15:51 user3266496 133 1 The semaphore set doesn't exist, or semid is less than zero, or nsops has a nonpositive value. Read the manual :) –user405725 Feb 3 '14 at 15:54 @VladLazarenko Semid returns success, what else should I check? –user3266496 Feb 3 '14 at 16:19 add a comment| 1 Answer 1 active oldest votes up vote 2 down vote Check if int semid = semget(key, sem, 0666); returns success or failure. As @VladLazaranenko mentioned there could be a lot of possible errors. Check every single return code for every single function you call (if they return a value) - for production systems. share|improve this answer answered Feb 3 '14 at 15:58 jim mcnamara 11.8k21637 Also, continually calling semget is almost certainly unnecessary. Once you have the semid, you have the semid. –Duck Feb 3 '14 at 16:02 Semid returns success, what else should I check? –user3266496 Feb 3 '14 at 16:10 @Duck I agree. But this is the only code I can see. If you make a call then check the return code. To the OP: review your code and make sure there are no error return codes. And you check return codes. That will eliminate a lot of possible causes. &ndas
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Semaphore error in Linux - :Invalid argument error no :22 (EINVAL) up vote 0 down vote favorite I am trying to execute a C program in linux and I am getting http://stackoverflow.com/questions/21531722/semop-invalid-argument error as "P_Semaphore :Invalid argument error no :22," can someone help 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"); } linux semaphore share|improve this question edited Nov 9 http://stackoverflow.com/questions/33606197/semaphore-error-in-linux-invalid-argument-error-no-22-einval '15 at 10:26 rghome 2,72711231 asked Nov 9 '15 at 9:40 Yogarajan 42 add a comment| 1 Answer 1 active oldest votes up vote 0 down vote According to the manual on semop(2) EINVAL The semaphore set doesn't exist, or semid is less than zero, or nsops has a nonpositive value. So in your case, nsops is zero (non-positive). It should be one. This is the third parameter of the call: int semop(int semid, struct sembuf *sops, size_t nsops); share|improve this answer edited Nov 9 '15 at 10:10 answered Nov 9 '15 at 9:43 rghome 2,72711231 I checked , the semaphore set exists, also with a positive value –Yogarajan Nov 9 '15 at 9:47 nsops is the third parameter to the semop call. It is zero and it should be 1. –rghome Nov 9 '15 at 9:48 no its not the problem I checked, I am getting error in the printf statement " printf( "%s(%d):Error semaphore making attempt %d,errno = %d\n", M_HEADER, i_sem_id, errno); " –Yogarajan Nov 9 '15 at 10:00 Please look again. The third parameter in your semop call is wrong. –rghome Nov 9 '15 at 10:05 You should up-vote and accept an answer when it correctly identifies the issue in your code. Then others who have the same problem can also benefit from your question and you can gain reputation poin
Mon, 2 Dec 2002 02:18:01 UTC Severity: normal Tags: patch Found in version 0.5.1 Fixed in version fakeroot/0.5.2 Done: Clint Adams
14:24 UTC From: gamr at gamrdev dot com Assigned: Status: Closed Package: APC (PECL) PHP Version: 5_1 CVS-2005-09-02 (dev) OS: Gentoo Linux Private report: No CVE-ID: View Add Comment Developer Edit [2005-09-02 11:22 UTC] gamr at gamrdev dot com Description: ------------ current apc and php from cvs, non thread safe [Tue Oct 4 01:40:40 2005] [apc-error] apc_sem_lock: semop(655371) failed: Invalid argument [Tue Oct 4 01:40:40 2005] [apc-error] apc_sem_lock: semop(655371) failed: Invalid argument [Tue Oct 4 01:40:40 2005] [apc-error] apc_sem_lock: semop(655371) failed: Invalid argument [Tue Oct 4 01:40:40 2005] [apc-error] apc_sem_lock: semop(655371) failed: Invalid argument [Tue Oct 4 01:40:40 2005] [apc-error] apc_sem_lock: semop(655371) failed: Invalid argument [Tue Oct 4 01:40:40 2005] [apc-error] apc_sem_lock: semop(655371) failed: Invalid argument [Tue Oct 4 01:40:40 2005] [apc-error] apc_sem_lock: semop(655371) failed: Invalid argument [Tue Oct 4 01:40:40 2005] [apc-error] apc_sem_lock: semop(655371) failed: Invalid argument [Tue Oct 4 01:40:40 2005] [apc-error] apc_sem_lock: semop(655371) failed: Invalid argument it takes roughly 8000 requests from apachebench to cause it to do it normally, testing against apc.php Patches Add a PatchPull Requests Add a Pull RequestHistoryAllCommentsChangesGit/SVN commitsRelated reports [2005-09-02 11:30 UTC] rasmus@php.net Stick with fcntl locking for now. eg. these configure flags: ./configure --enable-apc' --enable-apc-mmap --with-apxs And a php.ini block similar to this: extension=apc.so apc.enabled=1 apc.shm_segments=1 apc.optimization=0 apc.shm_size=64 apc.ttl=7200 apc.user_ttl=7200 apc.num_files_hint=500 apc.mmap_file_mask=/tmp/apc.XXXXXX apc.enable_cli=1 [2006-02-27 07:33 UTC] mike@php.net No feedback w