本帖最后由 wg4478 于 2012-03-02 17:31:38 编辑
/*父进程每3秒创建文件, 子进程每4秒读取打印并删除文件*/
/*Include Files*/
#include
#include
#include
#include
#include
#include
#include
/*MACRO*/
#define MAX 5
/*open file, and write*/
int parent(int i)
{
int fd_write;
unsigned bytes_write;
char buf[256];
char command[256];
char path[128];
memset(buf, 0, sizeof(buf));
memset(command, 0, sizeof(command));
memset(path, 0, sizeof(path));
sprintf(path, "./%d", i);
fd_write = open(path, O_CREAT | O_WRONLY | O_TRUNC, 0640);
sprintf(buf, "%s", "This is a test.");
bytes_write = write(fd_write, buf, sizeof(buf) - 1);
close(fd_write);
printf("The write bytes are %u.n", bytes_write);
sprintf(co