I have a problem fixing the 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():
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97

#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 on
This first line looks bogus:

52
53
54
55
56
    if ((Cid = shmget(IPC_CREAT, sizeof(matstr), IPC_CREAT)) < 0)
    {
        ...
    }


The first argument to shmget() is a key.

Have you already allocated the shared memory segment for that ID? What does "ipcs" tell you? Since you don't remove the the shared memory segment, you may have run out of resources.

It looks like you are getting this error:

       ENOSPC All possible shared memory IDs  have  been  taken  (SHMMNI),  or
              allocating  a segment of the requested size would cause the sys-
              tem to exceed the system-wide limit on shared memory (SHMALL).
Topic archived. No new replies allowed.