Thread: Need help with error " No space left on device : : Illegal seek"

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    6

    Need help with error " No space left on device : : Illegal seek"

    Hello, I'm trying to compile my professor's code but I get the error
    "No space left on device
    ./posted: : Illegal seek"

    Heres the code (its to multiply matrices using shmget() and fork():
    Code:
    #include <sys/types.h>
    #include <sys/ipc.h>
    #include <sys/shm.h>
    #include <sys/wait.h>
    #include <stdio.h>
    #include <malloc.h>
    #include <pthread.h>
    #include <math.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <errno.h>
    #include <error.h>
    
    /* N: size of each dimension. Give powers of two */
    #define DIM 1024
    
    /* TT: number of threads (want a square number).
     * Give powers of two to T.
     */
    #define T 2
    #define TT (T*T)
    
    /* This struct is used to define and access a 2D matrix
     * inside the shared memory segment
     */
    typedef struct matrixstruct {
        int C[DIM][DIM];
        } matstr;
    
    int **A;     /* input matrix A */
    int **B;     /* input matrix B */
    matstr *Cms; /* pointer to output matrix C */
    int Cid;     /* segment id for output matrix C */
    
    /* this function does the actual multiplication */
    void * doyourpart(void *);
    
    int main()
    {
        int i;
        int parts[TT];
    
        A = calloc(DIM, sizeof(int *));
        for (i=0; i < DIM; i++)
            A[i] = calloc(DIM, sizeof(int));
    
        B = calloc(DIM, sizeof(int *));
        for (i=0; i < DIM; i++)
            B[i] = calloc(DIM, sizeof(int));
    
        if ((Cid = shmget(IPC_CREAT, sizeof(matstr), IPC_CREAT)) < 0)
        {
            perror("smget returned -1\n");
            error(-1, errno, " ");
            exit(-1);
        }
        printf("Allocated %d, at id %d\n", (int) sizeof(matstr), Cid);
    
        if ((Cms = (matstr *) shmat(Cid, NULL, 0)) == (matstr *) -1)
        {
            perror("Process shmat returned NULL\n");
            error(-1, errno, " ");
        }
    
        for (i=0; i<TT; i++)
        {
            int id;
            parts[i] = i;
            if ((id=fork())==0)
            {/* child */
                doyourpart(&(parts[i]));
            }
            /* There is no else because doyourpart() calls exit.
             * If doyourpart() does not call exit, then will need
             * to add an else here
             */
        }
    
        printf("Parent process waiting\n");
        for (i=0; i<TT; i++)
            wait(NULL);
    
        return 0;
    
    }
    
    
    void *doyourpart(void *param)
    {
        int mypart = * ((int *)param);
    
    
        /* code goes here */
    
        exit(0);
    }
    Any help would be appreciated, thanks in advance.
    *Edit* Another compiler gives me the same error but also gives me "smget returned -1"
    Last edited by Uni616; 09-20-2010 at 03:25 PM.

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Do you know which function call is returning this error? According to the man page for shmget:

    [ENOSPC] A new shared memory identifier could not be created
    because the system limit for the number of shared mem-
    ory identifiers has been reached.
    It seems odd to me to use IPC_CREAT for the first argument to shmget, rather than the result of ftok.

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    6
    Hmm, I know shmget is returning -1, and that is what causing the error. I'm not that familiar with linux, and I'm not sure how to use ftok in this case. Commenting out the error checking will make it run, but the shared memory doesn't seem to work properly.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  2. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. Release Configuration Problems
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2002, 04:54 AM
  5. Please help me
    By teedee46 in forum C++ Programming
    Replies: 9
    Last Post: 05-06-2002, 11:28 PM