with shm_open, you can have a file descriptor pointing to shared memory and pass it to dup2, as shown below:
int fd = shm_open("shm-name", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); dup2(fd, STDOUT_FILENO); fprintf(stdout, "This is string is gonna be printed on shared memory");
And in the end, find the shared memory at the beginning (use lseek to read it and save it in a line, but be careful
You can also find an example of pipe buffering in Here.
source share