LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 07-07-2007, 10:17 AM   #1
clalfa
LQ Newbie
 
Registered: Jul 2007
Posts: 7

Rep: Reputation: 0
"No space left on device" error using SystemV shared memory


Hi everyone,

I am using SystemV shared memory and semaphores to let some processes exchange information.
I've used shmget function to create a shared memory area, shmat to attach it to each process, then shmdt and shmctl to detach and deallocate the memory I've used; as for semaphores, I've used semget and semctl.
The problem is, after I've launched the program 8-9 times apparently without problems, when I try to execute the program semget returns an error: no space left on device. What leaves me astonished is the fact that I've actually detached AND released all of the memory I've used, by calling shmdt in each process and shmctl in main process, and by using semctl only in main process.
Does anyone have any idea ???

I'm getting pretty messed up with that program, so please help me!!

thanks
 
Old 07-07-2007, 12:34 PM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 30
The problem you describe is not with shared memory, because you say the error occurs with semget(), which is concerned with semaphores, not shared memory. You probably have a semaphore leak.

In your description, you say that you delete all the shared memory, but do you delete all semaphores that you use?

That would be something to double-check.

Also, to help you figure this out, do this at the command line:

Code:
ipcs -a
man ipcs
Hope this helps.

Last edited by wjevans_7d1@yahoo.co; 07-07-2007 at 12:38 PM.
 
Old 07-07-2007, 07:14 PM   #3
clalfa
LQ Newbie
 
Registered: Jul 2007
Posts: 7

Original Poster
Rep: Reputation: 0
Hi wjevans!
First of all thank you for answering my post, I really appreciated your help!
I run my program a few times, then checked the ipc status with ipcs (that's REALLY useful ).
The output shows that each semaphore I've used in my program still exists!! Not only, I've also discovered that even shared memory areas aren't deallocated when the program is terminated: they're still in the list provided by ipcs, with 0 processes attached to them.
Basically, detachment is successful, but shared memory isn't really deallocated. Any idea?
This is how I call shmget, shmat, shmctl (to deallocate when detachment is done) and shmdt:

coord_buf_s_id = shmget (IPC_PRIVATE, COORD_DIM * sizeof(pos), IPC_CREAT | S_IRUSR | S_IWUSR );
coord_buf = shmat ( coord_buf_s_id, NULL, SHM_RND );
shmctl (coord_buf_s_id, IPC_RMID, NULL);
shmdt (coord_buf);

Since ipcs reports no precess is attached to shared segments, I suppose there's some kind of problem with shmctl...
As for semaphores, there's no need to attach/deattach, so I just call a
coord_mutex = semget (IPC_PRIVATE, 1, IPC_CREAT | S_IRUSR | S_IWUSR );
when program begins, then call
semctl (coord_mutex, 1, IPC_RMID, arg);
before the last process of the program exits.

Is my code OK?

Thank you in advance
 
Old 07-08-2007, 08:48 AM   #4
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 30
Here's my suggestion.

Run the following program. It allocates, attaches, removes, and detaches a shared memory segment.

When it has announced a new shmid, go to another terminal window and run ipcs. That should show you the new shmid.

Then go back to this program and press the <Enter> key. When you run ipcs again, you should notice that the new shmid has disappeared.

When you have confidence that the shared memory facility isn't broken (at least it wasn't for me), figure out what went wrong in your program.

Rinse and repeat for semaphores.

Code:
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
  int   coord_buf_s_id;

  char *coord_buf;

  char  answer[8];

  coord_buf_s_id=shmget(IPC_PRIVATE,
                        123,
                        IPC_CREAT|S_IRUSR|S_IWUSR
                       );

  if(coord_buf_s_id==-1)
  {
    perror("shmget()");

    exit(1);
  }

  coord_buf=shmat(coord_buf_s_id,
                  NULL,
                  SHM_RND
                 );

  if((int)coord_buf==-1)
  {
    perror("shmat()");

    exit(1);
  }

  printf("shmid %d has been created; press <Enter> to continue. >  ",
         coord_buf_s_id
        );

  fgets(answer,sizeof(answer),stdin);

  if(shmctl(coord_buf_s_id,
            IPC_RMID,
            NULL
           )
    )
  {
    perror("shmctl(,IPC_RMID,NULL)");

    exit(1);
  }

  if(shmdt(coord_buf))
  {
    perror("shmdt()");

    exit(1);
  }

  return 0;

} /* main() */
 
Old 07-08-2007, 11:59 AM   #5
clalfa
LQ Newbie
 
Registered: Jul 2007
Posts: 7

Original Poster
Rep: Reputation: 0
I've done what you suggested, and solved the problems with shared memory segments: the semctl was to be called BEFORE any detachment...
Unfortunately, the problem with semaphores remains: I've tried running a program like the one you've posted, and everything is ok. ipcs shows the semaphore is allocated, then deallocated when the process is terminated.
I thought the reason why semaphores were not deallocated was the fact that I did not use the flag SEM_UNDO when doing a wait or a signal: I thought there could be a process waiting on a waiting queue of that semaphore which blocked the deallocation, but then when I tried using SEM_UNDO nothing changed.
I really haven't got the faintes idea of what is wrong with my program...

Anyhow thank you so much for your help !!
 
Old 07-09-2007, 08:34 AM   #6
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 30
I hesitate to suggest this, partly because I know you've already thought of it and are already working on it, but:

If all else fails, have you thought of taking a destroyable copy of your program and ripping out chunks of it one at a time, testing it each time, as it becomes more and more like your (well-behaved) semaphore test program, until it works, and then focusing on what you ripped out that fixed the problem?

A lot of work, but sometimes that's the only thing that will work.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"No space left on device" error 1984 Slackware - Installation 6 03-08-2008 04:30 PM
"no space left on device" error. ekkasit Linux - General 5 07-08-2007 03:50 PM
Getting a "No space left on device" message on a non-full partition... sugar2 Linux - Hardware 12 07-06-2007 02:43 AM
"Cannot create directory: No space left on device" but I have 7.1G available !!!! fr_laz Linux - General 3 12-09-2005 05:44 PM
"no space left on device" - But df shows free space! monita Linux - General 7 03-30-2004 02:14 PM


All times are GMT -5. The time now is 08:35 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration