in my multi-process program, child processes change the array's context concurrently and parent reads. for the parent to read the array updated by the child processes, i am told to use pipe
and it worked! the problem is i cannot use ARRAY_SIZE
more than 65600ish, i need it to be 5000000.
so apparently, with fcntl
it can be changed.
in main
, i did this:
if(pipe(fd) == -1)
perror("pipe");
fcntl(fd[1],F_SETPIPE_SZ,5000000);
it says F_SETPIPE_SZ
is undeclared.
if i move it outside the main
, it says:
error: expected declaration specifiers or ‘...’ before numeric constant
instead of dealing with these, is there any other way to make the parent read the updated array? (this is an assignment so i don't think they'd push too hard to be honest, so i believe there must be an easier way)
edit: i wonder how to achieve this by not changing the pipe size. here is my code. this code does print what i want but it takes Total time = 1459086139.792471 seconds.
in this assignment the main idea is to see the difference between execution times of a single process program and a multi-process program. single process program takes 37 seconds. so, this result cannot be right, right? i tried to move the part after //another attempt
to the outside of the loop, it does not work, it does not give any errors too, does nothing.
for(j = 0; j<NUM_OF_SUBARRAYS; j++)
{
start = (SUBARRAY_SIZE*j);
child_pid = fork();
switch (child_pid)
{
case -1:
perror("fork");
exit(1);
case 0:
child_process_routine(start);
exit(0);
default:
waitpid(-1, NULL, 0);
//another attempt
close(fd[1]);
for (i = 0; i<ARRAY_SIZE; i++)
{
read(fd[0], &temp, sizeof(temp));
printf("%c ",temp);
}
close(fd[0]);
}
}