linux父子进程轮流交替数数,[新手求解]父子进程交替执行的问题

本帖最后由 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值