当前位置: 技术问答>linux和unix
父子进程拷文件程序的几处不懂得地方
来源: 互联网 发布时间:2017-01-08
本文导语: #include #include #include #include #include #include #include #define N 64 int main(int argc, char *argv[])//./copy src dest { int fdr, fdw; off_t len; pid_t pid; ssize_t n; char buf[N]; if (argc 0) write(fdw, buf, n); } else //parent...
#include
#include
#include
#include
#include
#include
#include
#define N 64
int main(int argc, char *argv[])//./copy src dest
{
int fdr, fdw;
off_t len;
pid_t pid;
ssize_t n;
char buf[N];
if (argc 0)
write(fdw, buf, n);
}
else //parent first 1/2
{
lseek(fdr, 0, SEEK_SET);
lseek(fdw, 0, SEEK_SET);
while ((n = read(fdr, buf, N)) > 0)
{
write(fdw, buf, n);
len -= n;
if (len
#include
#include
#include
#include
#include
#include
#define N 64
int main(int argc, char *argv[])//./copy src dest
{
int fdr, fdw;
off_t len;
pid_t pid;
ssize_t n;
char buf[N];
if (argc 0)
write(fdw, buf, n);
}
else //parent first 1/2
{
lseek(fdr, 0, SEEK_SET);
lseek(fdw, 0, SEEK_SET);
while ((n = read(fdr, buf, N)) > 0)
{
write(fdw, buf, n);
len -= n;
if (len