6.11zuoye

 图片拷贝

 #include "stdio.h"
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
  #include <unistd.h>
 
 int main(int argc, const char *argv[])
 {
     int p_r=open("./1.png",O_RDONLY);
     int p_w=open("./2.png",O_WRONLY|O_CREAT|O_TRUNC,0777);
     off_t size=lseek(p_r,0,SEEK_END);
     pid_t pid=fork();
     if(pid>0)
     {
         sleep(3);
         lseek(p_r,0,SEEK_SET);
         lseek(p_w,0,SEEK_SET);
         char c;
         for(int i=0;i<size/2;i++)
         {
             read(p_r,&c,1);
             write(p_w,&c,1);
         }
         printf("父线程拷贝完毕\n");
     }
     if(pid==0)
     {
         lseek(p_r,size/2,SEEK_SET);
         lseek(p_w,size/2,SEEK_SET);
         
         char arr[30];
         ssize_t res;                                                  
         while(res!=0)
         {
             res=read(p_r,arr,29);
             write(p_w,arr,res);
         }
     printf(".............\n");
     }
     close(p_r);
     close(p_w);
     return 0;
 }

信息查询

 #include "stdio.h"
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <time.h>
 #include <dirent.h>
 #include <errno.h>
 #include <unistd.h>
 #include <string.h>
 
 int main(int argc, const char *argv[])
 {
     FILE* pb=fopen("./txt","w");
     if(pb==NULL)
     {
         perror("fopen");
         return -1;
     }
     printf("文件打开成功\n");
     DIR *dir=opendir("../100t/");
     if(NULL==dir)
     {
         perror("opendir");
         return -1;
     }
     printf("文件夹打开成功\n");
     struct dirent *dp;
     char name[256]="";
     struct stat buf;
     struct tm* info;
     while(1)
     {
         dp=readdir(dir);
         if(dp==NULL)
         {
             if(errno==0)
             {
                 printf("w文件读取成功\n");
             }
             else
             {
                 perror("readdir");
                 return -1;
 
             }
         }
         if(dp->d_name[0]=='.')
         {
             continue;
         }
         fprintf(pb,"%s\t",dp->d_name);
         stat(dp->d_name,&buf);
         info=localtime(&buf.st_ctim);
         fprintf(pb,"%o %04d-%02d-%02d-%02d-%02d %s\n",buf.st_mode & 0777,\
                 info->tm_year+1900,info->tm_mon+1,info->tm_mday,\
                 info->tm_hour,info->tm_min,dp->d_name);
     }
     closedir(dir);
     fclose(pb);
                                                                                                           
 
 
 
 
     return 0;
 }
                                                                                                           

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值