#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <err.h>

#define SLEEP 15

int main(int argc, char *argv[])
{
	int fd1,fd2;
	char *f1 = argv[1];
	char *f2 = argv[2];
	char buf[1000]= {0,};
	char wrbuf[200];
	int ret;

	assert(argc == 3);

	printf("write to: %s\nread from: %s\n\n",
	       f1, f2);

	fd1 = open(f1, O_RDWR);
	fd2 = open(f2, O_RDONLY);
	if (fd1 < 0 || fd2 < 0)
		err(1, "error open");
		
	sprintf(wrbuf, "test message-%d", getpid());
	printf("Write: [%s]\n", wrbuf);
	ret = write(fd1, wrbuf, strlen(wrbuf));
	if (ret < 0)
		err(1, "error write");

	sleep(1);
	ret = read(fd2, buf, sizeof(buf) - 1);
	if (ret < 0)
		err(1, "error read");
	printf("Read:  [%s]\n", buf);
	return 0;
}

