0

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]);
        }
    }
  • 1
    The upper bound is likely to be 65535 (2^16 - 1). You can find [`F_SETPIPE_SZ`](http://man7.org/linux/man-pages/man2/fcntl.2.html) in `` if you have a sufficiently recent version of Linux. Why do you need the limit to be bigger? If you design the data on the wire properly and have a single reader thread/process, then you can write and read the data unambiguously. – Jonathan Leffler Mar 27 '16 at 01:05
  • i do have a single reader process which is the parent. there is a `for` loop which creates child processes, in its `default` case (in parent code) it waits for the child processes. after for loop, parent's code can continue, right? i put the `read` code there. it didn't work. (no error, just nothing happened) i put the `read` code in `default` case after wait. it prints the elements, but never stops –  Mar 27 '16 at 13:31
  • i added more information, please check –  Mar 27 '16 at 13:40
  • The printed 'total time' value is the current UNIX time stamp, not the time your program was running. The duplicate question deals with why you get the `F_SETPIPE_SZ` undefined error. You can't afford to ignore the return value from `read()`. You should be reading more than one byte at a time. There is nowhere near enough code for this to be an MCVE ([MCVE]), and without an MCVE, it will be hard to help you. Pay attention to the duplicate. Ask a new question with an MCVE. – Jonathan Leffler Mar 27 '16 at 15:07

0 Answers0