parent
e306830003
commit
97f9196db6
@ -0,0 +1,9 @@ |
||||
#include <stddef.h> |
||||
#include <sys/time.h> |
||||
|
||||
double dtime(void) |
||||
{ |
||||
struct timeval tv; |
||||
gettimeofday(&tv, NULL); |
||||
return (double)tv.tv_sec + ((double)tv.tv_usec)/1e6; |
||||
} |
@ -0,0 +1,27 @@ |
||||
/*** named pipe --- receiver ***/ |
||||
|
||||
#include <stdio.h> |
||||
#include <stdlib.h> |
||||
#include <unistd.h> |
||||
#include <sys/stat.h> /* for mkfifo */ |
||||
#include <fcntl.h> |
||||
#include "my-fifo.h" |
||||
|
||||
int main(int argc, char *argv[]) |
||||
{ |
||||
int fifo; |
||||
Message message; |
||||
double localTS; |
||||
|
||||
if (argc!=2) exit(1); |
||||
fifo = mkfifo(argv[1], 0400); |
||||
if (fifo) { |
||||
perror("mkfifo fail"); |
||||
exit(2); |
||||
} |
||||
read(fifo, &message, sizeof(Message)); |
||||
localTS = dtime(); |
||||
printf("%f %f\n", localTS, message.timestamp); |
||||
close(fifo); |
||||
return 0; |
||||
} |
@ -0,0 +1,24 @@ |
||||
/*** named pipe --- transmiter ***/ |
||||
#include <stdio.h> |
||||
#include <stdlib.h> |
||||
#include <unistd.h> |
||||
#include <fcntl.h> |
||||
#include "my-fifo.h" |
||||
|
||||
int main(int argc, char *argv[]) |
||||
{ |
||||
int fifo; |
||||
Message message; |
||||
|
||||
if (argc!=2) exit(1); |
||||
if (-1==(fifo = open(argv[1], O_WRONLY))) { |
||||
perror("open fifo for wr"); |
||||
exit(1); |
||||
} |
||||
message.pid = getpid(); |
||||
message.timestamp = dtime(); |
||||
write(fifo, &message, sizeof(Message)); |
||||
close(fifo); |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,7 @@ |
||||
typedef struct { |
||||
int pid; |
||||
double timestamp; |
||||
long notused; |
||||
} Message; |
||||
|
||||
double dtime(void); |
Loading…
Reference in new issue