0 Replies - 537 Views - Last Post: 09 February 2013 - 08:23 PM Rate Topic: -----

#1 apaddobs  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 49
  • Joined: 16-May 12

Semaphore : semget returning ENOENT

Posted 09 February 2013 - 08:23 PM

$ cat sem.cc
#include <sys/sem.h>
 #include <sys/stat.h>
#include <cerrno>
#include <iostream>
using namespace std;

main () {
    string key = "/m/lb1/activity.log";
    int sem_key = ftok (key.c_str (), 1);
    if (access (key.c_str (), R_OK) == 0)
        printf ("keypath is accessible \n");
    printf("sem_getid : %d", sem_key);
    errno = 0;
    int sem_id = semget (sem_key, 0, 0655);
    printf( " sem get val :%d :%s\n", sem_id, strerror(errno));
}
$ ./a.out
keypath is accessible 
sem_getid : 16850172 sem get val :-1 :No such file or directory





ls -l /m/lb1/activity.log
-rw-r--r-- 1 apple g6 0 Feb 9 19:08 /m/lb1/activity.log


The "access" call returns 0; so the keypath gets printed out. However, the semget is returning an ENOENT (No such file or directory)

sem_getid : 16850172
sem get val :-1 :No such file or directory

What could be wrong here?

This post has been edited by apaddobs: 09 February 2013 - 08:29 PM


Is This A Good Question/Topic? 0
  • +

Page 1 of 1