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"