LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-26-2012, 02:47 AM   #1
Vinay L
LQ Newbie
 
Registered: Jun 2012
Posts: 6

Rep: Reputation: Disabled
Semid not available in second process


Hi All,

I am using Semaphores for one of my application on Mac OS(10.5). I am able to successfully create the semaphores, but I am not able to get the semid in another process. I can see the list of semaphores using ipcs command.


The Code Snippet is as follows:

First_Process:


#include<stdio.h>
#include <string.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/shm.h>
#include <errno.h>

#define NUMSEMS 1

int main() {

int semid;

semid = semget("SEMTEST", NUMSEMS, 0666 | IPC_CREAT | IPC_EXCL);

printf("Sem id %d\n", semid);

return 0;
}

After running the above code’s executable, semaphore is created. I can verify using ipcs command.


$ipcs –s

Semaphores:

s 212860928 0x00001f68 --ra-ra-ra- offshore staff


After this I run my second process.

Second_Process:



#include<stdio.h>
#include <string.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/shm.h>
#include <errno.h>


#define NUMSEMS 1

int main() {

int semid;

int i;

semid = semget("SEMTEST", NUMSEMS, 0);

printf("----Semid=%d---\n", semid);

return 0;

}

The output of the second process is -1, i.e it is getting semid as -1 eventhough the semkey, NUMSEMS is same(as provided in first process).

Please let me know the changes to be done, so that we can get semid in Second Process also.



Thanks & Regards,
Vinay
 
Old 06-27-2012, 07:58 AM   #2
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,642
Blog Entries: 4

Rep: Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933
And what is the (symbolic) value of errno?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to kill or clean a Uninterruptible slept session leader process from process tabl golden_boy615 Linux - General 1 12-14-2010 10:47 AM
Finding the Process ID of a Process While Initiating the Process senthilmuthiah Linux - Newbie 7 04-02-2009 10:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration