I'd like to place an advisory write lock on a pipe file descriptor, but apparently that's not supported:
I'm running FreeBSD 9.1-RELEASE (amd64.) I've also tried using flock(2) instead of fcntl(2).
Is there something wrong with my arguments? Can I enable it in my kernel? My objective is to properly interleave line output from multiple processes, which will often then be piped into another command.
Thanks!
Kevin Barry
edit: One workaround is to send the output to a temp file and tail -f that into the next process in the chain, although that adds a few more steps, maybe another session, and extra disk I/O to the process.
Code:
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
int main(int argc, char *argv[])
{
struct flock set_lock = { l_type: F_WRLCK, l_whence: SEEK_CUR };
if (fcntl(1, F_SETLKW, &set_lock, NULL) == -1)
{
fprintf(stderr, "%s\n", strerror(errno));
return 1;
}
else fprintf(stderr, "fine\n");
}
Code:
> gcc test.c -o test
> ./test
[B]fine[/B]
> ./test | cat
[B]Bad file descriptor[/B]
Is there something wrong with my arguments? Can I enable it in my kernel? My objective is to properly interleave line output from multiple processes, which will often then be piped into another command.
Thanks!
Kevin Barry
edit: One workaround is to send the output to a temp file and tail -f that into the next process in the chain, although that adds a few more steps, maybe another session, and extra disk I/O to the process.