So you mean like (words can mix up stuff):
#include <sys/stat.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
int main(int argc, char **argv)
{
char *line = NULL;
struct stat sb;
size_t len;
int fds[2];
pid_t pid;
ssize_t n;
if (pipe(fds) < 0) {
perror("pipe");
exit(1);
}
pid = fork();
if (pid < 0) {
perror("fork");
exit(1);
}
if (pid == 0) {
dup2(fds[1], STDOUT_FILENO);
close(fds[0]);
close(fds[1]);
if (fstat(STDOUT_FILENO, &sb) < 0) {
perror("fstat");
exit(1);
}
printf("child: st_dev=%u, st_ino=%llu\n", sb.st_dev, sb.st_ino);
} else {
dup2(fds[0], STDIN_FILENO);
if (fstat(fds[1], &sb) < 0) {
perror("fstat");
exit(1);
}
printf("parent: st_dev=%u, st_ino=%llu\n", sb.st_dev, sb.st_ino);
close(fds[0]);
close(fds[1]);
n = getline(&line, &len, stdin);
if (n < 0) {
fprintf(stderr, "Unexpected EOF\n");
exit(1);
}
fwrite(line, n, 1, stdout);
free(line);
wait(&pid);
}
exit(0);
}
? With M1 generation MacBook Pro I get:
$ ./test
parent: st_dev=0, st_ino=9204210306621897207
child: st_dev=0, st_ino=9204210306621897207
@josh the two I know of are
(Well, they will be all equal, technically... but also equal to that of any other pipe)
@josh so like systemd's JOURNAL_STREAM? (But that one only has to work on Linux of course.)