problem with shared memory - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


problem with shared memory

i'm trying to read a file into shared memory so children of the process will be able to read it in parallel
here is the code i'v written
i posted only the beginning. when i try to print the ouput i see no output. i use this command to print
i also tried with %d and with write.
[code]int main(int argc, char *argv[]) {

char *shared1; // the shared memory will be attached to it
long long int size;
int i, fd, proc = atoi(argv[2]), num_of_byte = atoi(argv[3]), shmid, type = 2, read_test, fdfork;
if (argc < 4) {
perror("not enough arguments");
if (strcmp(argv[4], "signed") == 0) {
type = 10;
fd = open(argv[1], O_RDONLY, 0600);
if (fd == -1) {

struct stat st;
stat(argv[1], &st);
size = st.st_size / num_of_byte;
//create IPC memory
if ((shmid = shmget(IPC_PRIVATE, (st.st_size + 1), 0600 | IPC_CREAT)) < 0) {
perror("shmget error");
// attach the shared memory segment to the right shared memory type

if ((shared1 = shmat(shmid, NULL, 0)) == (char*) -1) {
perror("shmat error");
read_test = read(fd, shared1, st.st_size);
if (read_test == -1) {
Sign In or Register to comment.