文件的拷贝
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
#include <sys/types.h>
#include <string.h>
#include <stdlib.h>
int main(int argc ,const char * argv[])
{
// DIR * dir = opendir("/home/killer/桌面/TXT");
DIR * dir = opendir(argv[1]);
if(dir == NULL)
{
perror("C");
return 0;
}
struct dirent *file;
char path[256]={0};
strcat(path,argv[2]);
char filename[256]="mkdir ";
strcat(filename,path);
system(filename);
while((file = readdir(dir)))
{
int rfd = open(file->d_name,O_RDONLY);
//printf("%s\n",file->d_name);
//char path[256]="/home/killer/桌面/dest/";
char path1[256] = {0};
strcat(path1,path);
strcat(path1,file->d_name);
// printf("%s\n",path);
int wfd = open(path,O_WRONLY | O_TRUNC | O_CREAT,0666);
char buf[1024]={0};
while(read(rfd,buf,1023))
write(wfd,buf,1023);
}
}
创建100个进程
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
#include <sys/types.h>
#include <string.h>
#include <stdlib.h>
int main()
{
pid_t pid;
int i=0;
for(i=0;i<99;i++)
{
pid = fork();
if(pid==-1)
{
perror("");
}
else if (pid==0)
{
break;
}
}
if(pid > 0)
{
printf("进程%d\n",i);
}
else if (pid == 0)
{
printf("hello%d\n",i);
}
return 0;
}