62 lines
1.5 KiB
C
62 lines
1.5 KiB
C
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <fcntl.h> /* Definition of AT_* constants */
|
|
#include <unistd.h>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
|
|
static const char *kat = "/tmp/FIFO-TMP-SERWER";
|
|
static const char *kat_1 = "/tmp/FIFO-TMP-1-";
|
|
static const char *kat_2 = "/tmp/FIFO-TMP-2-";
|
|
|
|
int main()
|
|
{
|
|
int f, f1, f2;
|
|
pid_t pid = getpid();
|
|
printf("pid: %d\n", pid);
|
|
char kat_1_pid[100];
|
|
char kat_2_pid[100];
|
|
strcpy(kat_1_pid, kat_1);
|
|
strcpy(kat_2_pid, kat_2);
|
|
sprintf(kat_1_pid + strlen(kat_1), "%d", pid);
|
|
sprintf(kat_2_pid + strlen(kat_2), "%d", pid);
|
|
// printf(kat_1_pid);
|
|
// printf(kat_2_pid);
|
|
if ((f = open(kat, O_WRONLY)) == -1)
|
|
{
|
|
printf("kat open error\n");
|
|
return;
|
|
}
|
|
if (mkfifo(kat_1_pid, 0600) == -1)
|
|
{
|
|
printf("mkfifo1 open error\n");
|
|
return;
|
|
}
|
|
if (mkfifo(kat_2_pid, 0600) == -1)
|
|
{
|
|
printf("mkfifo2 open error\n");
|
|
return;
|
|
}
|
|
write(f, &pid, sizeof(pid_t));
|
|
close(f);
|
|
if ((f2 = open(kat_2_pid, O_WRONLY)) == -1)
|
|
{
|
|
printf("kat2 open error\n");
|
|
return;
|
|
}
|
|
printf("f2 open\n");
|
|
if ((f1 = open(kat_1_pid, O_RDONLY)) == -1)
|
|
{
|
|
printf("kat1 open error\n");
|
|
return;
|
|
}
|
|
printf("f1 open\n");
|
|
double d2, d = 10.0;
|
|
write(f2, &d, sizeof(double));
|
|
read(f1, &d2, sizeof(double));
|
|
close(f1);
|
|
close(f2);
|
|
unlink(kat_1_pid);
|
|
unlink(kat_2_pid);
|
|
printf("%f\n", d2);
|
|
} |