Jump to content

I have a problem fixing the error " No space left on device : Illegal seek

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
Uni616

Uni616

    Newbie

  • Members
  • Pip
  • 2 posts
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(shared memory) and fork):


#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.
Another compiler gives me the same error but also gives me "smget returned -1"
Also, I tried commenting out the error checking, it runs but the shared memory doesn't seem to work properly.

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
How many processes do you have created when you get the error? It's not clear to me that your forks aren't also creating a ton of processes.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog