<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Problem with Semaphores in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-semaphores/m-p/5053668#M746261</link>
    <description>You code doesn't compile with aC++, you need to fully prototype everything.&lt;BR /&gt;&lt;BR /&gt;You are illegally passing the wrong type to parm 4 of semctl.  You are required to pass union semun but you are passing an int.&lt;BR /&gt;&lt;BR /&gt;You neglected to mention you were compiling on IPF or using PA64.&lt;BR /&gt;&lt;BR /&gt;(In SemCreate you are printing the value of *semid before you initialize it.)</description>
    <pubDate>Tue, 19 Jun 2007 22:42:52 GMT</pubDate>
    <dc:creator>Dennis Handly</dc:creator>
    <dc:date>2007-06-19T22:42:52Z</dc:date>
    <item>
      <title>Problem with Semaphores</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-semaphores/m-p/5053667#M746260</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;We are trying to access a Semaphore memory for a particular process.Below is the code that we are using. We are able to access the Semaphore and set the values successfully. But value 0 is returned when we try to use the getval function of semctl. The actual value that has to be returned is, 1. This semaphore is not used by any other program. We are not aware why it is returning this value. Any help in this regard will be greatly appreciated.&lt;BR /&gt;&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;SIGNAL.H&gt;&lt;BR /&gt;#include &lt;SYS&gt;&lt;BR /&gt;&lt;BR /&gt;int main()&lt;BR /&gt;{&lt;BR /&gt;int semid;&lt;BR /&gt;  if (SemAccess(&amp;amp;semid, 0x321))&lt;BR /&gt;  {&lt;BR /&gt;        printf("Into SemCreate");&lt;BR /&gt;        SemCreate(&amp;amp;semid, 0x321);&lt;BR /&gt;  }&lt;BR /&gt;&lt;BR /&gt;  if (!SemAvailable(semid))&lt;BR /&gt;    {&lt;BR /&gt;      printf("No");&lt;BR /&gt;      }&lt;BR /&gt;  else&lt;BR /&gt;        printf("Yes");&lt;BR /&gt;&lt;BR /&gt;return(0);&lt;BR /&gt;}&lt;BR /&gt;int SemAccess(int *semid, int key)&lt;BR /&gt;{&lt;BR /&gt;   int sem;&lt;BR /&gt;&lt;BR /&gt;     sem = semget(key, 1, 0666);&lt;BR /&gt;    if (sem != -1)&lt;BR /&gt;    {&lt;BR /&gt;     *semid = sem;&lt;BR /&gt;     printf("\nCan Access Sem %d\n",*semid);&lt;BR /&gt;     }&lt;BR /&gt;     return(sem == -1);&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; int SemCreate(int *semid, int key)&lt;BR /&gt; {&lt;BR /&gt;    int sem;&lt;BR /&gt;&lt;BR /&gt;  sem = semget(key, 1, 0666 | IPC_CREAT | IPC_EXCL);&lt;BR /&gt;  printf("\nSem Created%d\n", *semid);&lt;BR /&gt;     if (sem != -1)&lt;BR /&gt;     {&lt;BR /&gt;      *semid = sem;&lt;BR /&gt;       semctl(sem, 0, SETVAL, 1);       /* initially released */&lt;BR /&gt;       printf("\nSem Created%d\n", semctl(sem, 0, SETVAL, 1));&lt;BR /&gt;      }&lt;BR /&gt;          return(sem == -1);&lt;BR /&gt;  }&lt;BR /&gt;int SemAvailable(int semid)&lt;BR /&gt;{&lt;BR /&gt;   printf("\n%d\n",semctl(semid, 0, GETVAL));&lt;BR /&gt;   return(semctl(semid, 0, GETVAL));&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;&lt;BR /&gt;nan&lt;/SYS&gt;&lt;/SIGNAL.H&gt;&lt;/STDIO.H&gt;</description>
      <pubDate>Tue, 19 Jun 2007 08:35:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-semaphores/m-p/5053667#M746260</guid>
      <dc:creator>rajanandhini</dc:creator>
      <dc:date>2007-06-19T08:35:51Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Semaphores</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-semaphores/m-p/5053668#M746261</link>
      <description>You code doesn't compile with aC++, you need to fully prototype everything.&lt;BR /&gt;&lt;BR /&gt;You are illegally passing the wrong type to parm 4 of semctl.  You are required to pass union semun but you are passing an int.&lt;BR /&gt;&lt;BR /&gt;You neglected to mention you were compiling on IPF or using PA64.&lt;BR /&gt;&lt;BR /&gt;(In SemCreate you are printing the value of *semid before you initialize it.)</description>
      <pubDate>Tue, 19 Jun 2007 22:42:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-semaphores/m-p/5053668#M746261</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-06-19T22:42:52Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Semaphores</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-semaphores/m-p/5053669#M746262</link>
      <description>Your point assignment ratio is low, you need to address this before you are struck off. :-)&lt;BR /&gt;&lt;A href="http://forums1.itrc.hp.com/service/forums/helptips.do?#33" target="_blank"&gt;http://forums1.itrc.hp.com/service/forums/helptips.do?#33&lt;/A&gt;&lt;BR /&gt;&lt;A href="http://forums1.itrc.hp.com/service/forums/pageList.do?userId=CA1482177&amp;amp;listType=unassigned&amp;amp;forumId=1" target="_blank"&gt;http://forums1.itrc.hp.com/service/forums/pageList.do?userId=CA1482177&amp;amp;listType=unassigned&amp;amp;forumId=1&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 19 Jun 2007 22:56:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-semaphores/m-p/5053669#M746262</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-06-19T22:56:34Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Semaphores</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-semaphores/m-p/5053670#M746263</link>
      <description>&amp;lt;&lt;YOU neglected="" to="" mention="" you="" were="" compiling="" on="" ipf="" or="" using="" pa64.=""&gt;&lt;/YOU&gt;&lt;BR /&gt;We are compiling using IPF&lt;BR /&gt;&lt;BR /&gt;&amp;lt;&lt;YOUR point="" assignment="" ratio="" is="" low=""&gt;&lt;/YOUR&gt;&lt;BR /&gt;I am really sorry that i did not assign points for all the threads. I have now assigned for the same.</description>
      <pubDate>Tue, 19 Jun 2007 23:22:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-semaphores/m-p/5053670#M746263</guid>
      <dc:creator>rajanandhini</dc:creator>
      <dc:date>2007-06-19T23:22:55Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Semaphores</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-semaphores/m-p/5053671#M746264</link>
      <description>&amp;lt;&lt;YOU are="" illegally="" passing="" the="" wrong="" type="" to="" parm="" 4="" of="" semctl.="" you="" are="" required="" to="" pass="" union="" semun="" but="" you="" are="" passing="" an="" int.=""&gt;&lt;BR /&gt;&lt;BR /&gt;I have now tried to pass a union but still the semaphore is not available for use.&lt;BR /&gt;&lt;BR /&gt;please help&lt;/YOU&gt;</description>
      <pubDate>Wed, 20 Jun 2007 23:19:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-semaphores/m-p/5053671#M746264</guid>
      <dc:creator>rajanandhini</dc:creator>
      <dc:date>2007-06-20T23:19:51Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Semaphores</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-semaphores/m-p/5053672#M746265</link>
      <description>&amp;gt;I have now tried to pass a union but still the semaphore is not available for use.&lt;BR /&gt;&lt;BR /&gt;This worked fine for me.  I did have to use "ipcrm -s" to start all over.&lt;BR /&gt;&lt;BR /&gt;If this doesn't solve it, please attach your latest source.</description>
      <pubDate>Wed, 20 Jun 2007 23:38:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-semaphores/m-p/5053672#M746265</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-06-20T23:38:05Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Semaphores</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-semaphores/m-p/5053673#M746266</link>
      <description>Please find the below code and kindly let me know where I have gone wrong.&lt;BR /&gt;&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;SIGNAL.H&gt;&lt;BR /&gt;#include &lt;SYS&gt;&lt;BR /&gt;union samp&lt;BR /&gt;{&lt;BR /&gt;        int p;&lt;BR /&gt;}&lt;BR /&gt;q;&lt;BR /&gt;&lt;BR /&gt;int main()&lt;BR /&gt;{&lt;BR /&gt;int semid;&lt;BR /&gt;  if (SemAccess(&amp;amp;semid, 0x321))&lt;BR /&gt;  {&lt;BR /&gt;        printf("Into SemCreate");&lt;BR /&gt;        SemCreate(&amp;amp;semid, 0x321);&lt;BR /&gt;  }&lt;BR /&gt;&lt;BR /&gt;  if (!SemAvailable(semid))&lt;BR /&gt;    {&lt;BR /&gt;      printf("No");&lt;BR /&gt;      }&lt;BR /&gt;  else&lt;BR /&gt;        printf("Yes");&lt;BR /&gt;&lt;BR /&gt;return(0);&lt;BR /&gt;}&lt;BR /&gt;int SemAccess(int *semid, int key)&lt;BR /&gt;{&lt;BR /&gt;   int sem;&lt;BR /&gt;&lt;BR /&gt;     sem = semget(key, 1, 0666);&lt;BR /&gt;    if (sem != -1)&lt;BR /&gt;    {&lt;BR /&gt;     *semid = sem;&lt;BR /&gt;     printf("\nCan Access Sem %d\n",*semid);&lt;BR /&gt;     }&lt;BR /&gt;        return(sem == -1);&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; int SemCreate(int *semid, int key)&lt;BR /&gt; {&lt;BR /&gt;    int sem;&lt;BR /&gt;&lt;BR /&gt;  sem = semget(key, 1, 0666 | IPC_CREAT | IPC_EXCL);&lt;BR /&gt;  printf("\nSem Created%d\n", *semid);&lt;BR /&gt;     if (sem != -1)&lt;BR /&gt;     {&lt;BR /&gt;      *semid = sem;&lt;BR /&gt;       semctl(sem, 0, SETVAL, q.p);       /* initially released */&lt;BR /&gt;       printf("\nSem Created%d\n", *semid);&lt;BR /&gt;      }&lt;BR /&gt;          return(sem == -1);&lt;BR /&gt;  }&lt;BR /&gt;int SemAvailable(int semid)&lt;BR /&gt;{&lt;BR /&gt;   printf("\n%d\n",semctl(semid, 0, GETVAL));&lt;BR /&gt;   return(semctl(semid, 0, GETVAL));&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;nan&lt;/SYS&gt;&lt;/SIGNAL.H&gt;&lt;/STDIO.H&gt;</description>
      <pubDate>Wed, 20 Jun 2007 23:43:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-semaphores/m-p/5053673#M746266</guid>
      <dc:creator>rajanandhini</dc:creator>
      <dc:date>2007-06-20T23:43:49Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Semaphores</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-semaphores/m-p/5053674#M746267</link>
      <description>&lt;!--!*#--&gt;&amp;gt;kindly let me know where I have gone wrong.&lt;BR /&gt;&lt;BR /&gt;Well that's one way to get it wrong.  ;-)&lt;BR /&gt;You were still passing an int, not the union and didn't set it to 1.  And you should specify all the union members.&lt;BR /&gt;&lt;BR /&gt;union semun {&lt;BR /&gt;   int val;&lt;BR /&gt;   struct semid_ds *buf;&lt;BR /&gt;   ushort *array;&lt;BR /&gt;};&lt;BR /&gt;&lt;BR /&gt;int SemCreate(int *semid, int key) {&lt;BR /&gt;   union semun arg;&lt;BR /&gt;   int tmp;&lt;BR /&gt;   int sem = semget(key, 1, 0666 | IPC_CREAT | IPC_EXCL);&lt;BR /&gt;   if (sem != -1) {&lt;BR /&gt;      *semid = sem;&lt;BR /&gt;      printf("Sem Created: %d\n", *semid);&lt;BR /&gt;#ifdef FIX&lt;BR /&gt;      arg.val = 1;&lt;BR /&gt;      tmp = semctl(sem, 0, SETVAL, arg); /* initially released */&lt;BR /&gt;#else&lt;BR /&gt;      tmp = semctl(sem, 0, SETVAL, 1); /* initially released */&lt;BR /&gt;#endif&lt;BR /&gt;      printf("Sem SETVAL: %d\n", tmp);&lt;BR /&gt;   }&lt;BR /&gt;   return sem == -1;&lt;BR /&gt;}</description>
      <pubDate>Wed, 20 Jun 2007 23:59:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-semaphores/m-p/5053674#M746267</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-06-20T23:59:44Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Semaphores</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-semaphores/m-p/5053675#M746269</link>
      <description>Thanks a lot!!!!&lt;BR /&gt;&lt;BR /&gt;You are terrific!!!&lt;BR /&gt;&lt;BR /&gt;It has solved our problem..&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;&lt;BR /&gt;nan</description>
      <pubDate>Thu, 21 Jun 2007 00:20:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-semaphores/m-p/5053675#M746269</guid>
      <dc:creator>rajanandhini</dc:creator>
      <dc:date>2007-06-21T00:20:16Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Semaphores</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-semaphores/m-p/5053676#M746271</link>
      <description>If you are happy with your answers, you should close the thread so people know you don't need any more help.</description>
      <pubDate>Thu, 21 Jun 2007 04:15:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-semaphores/m-p/5053676#M746271</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-06-21T04:15:01Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Semaphores</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-semaphores/m-p/5053677#M746273</link>
      <description>I have got a solution. Thanks for the assistance</description>
      <pubDate>Thu, 21 Jun 2007 05:24:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-semaphores/m-p/5053677#M746273</guid>
      <dc:creator>rajanandhini</dc:creator>
      <dc:date>2007-06-21T05:24:49Z</dc:date>
    </item>
  </channel>
</rss>

