This commit is contained in:
tth
2021-08-28 17:06:26 +02:00
parent 97f9196db6
commit f5b9cf17dc
5 changed files with 28 additions and 5 deletions

View File

@@ -24,6 +24,8 @@ no-op: no-op.c Makefile
get-signal: get-signal.c Makefile
gcc -Wall $< -o $@
fifo: fifo-rx fifo-tx
dtime.o: dtime.c my-fifo.h Makefile
gcc -Wall -c $<

View File

@@ -1,6 +1,6 @@
#include <stddef.h>
#include <sys/time.h>
#include "my-fifo.h"
double dtime(void)
{
struct timeval tv;

View File

@@ -13,9 +13,12 @@ int fifo;
Message message;
double localTS;
if (argc!=2) exit(1);
fifo = mkfifo(argv[1], 0400);
if (fifo) {
if (argc!=2) {
fprintf(stderr, "%s need a fifo name\n", argv[0]);
exit(1);
}
fifo = mkfifo(argv[1], O_RDONLY|O_CREAT);
if (-1==fifo) {
perror("mkfifo fail");
exit(2);
}

View File

@@ -1,6 +1,7 @@
/*** named pipe --- transmiter ***/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include "my-fifo.h"
@@ -15,6 +16,7 @@ if (-1==(fifo = open(argv[1], O_WRONLY))) {
perror("open fifo for wr");
exit(1);
}
memset(&message, 0, sizeof(Message));
message.pid = getpid();
message.timestamp = dtime();
write(fifo, &message, sizeof(Message));