IO进程线程

cs 复制代码
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <dirent.h>
void file_copy(const char* rfile,const char* wfile){
	int res=-2;
	int rfd=open(rfile,O_RDONLY);
		if(rfd==-1){
			printf("读取的文件不存在\n");
			return;
		}
	int wfd=open(wfile,O_WRONLY|O_CREAT|O_TRUNC,0664);
	if(wfd==-1){return;}
	while(1){
		char data[2]={0};
		res=read(rfd,data,2);
		if(res==0){break;}
		write(wfd,data,2);
	}
	close(rfd);
	close(wfd);
int main(int argc, const char *argv[])
{
	struct stat buf={0};
	stat(argv[1],&buf);
	mode_t mode=buf.st_mode;
	if(S_ISDIR(mode)){
		mkdir(argv[2],0755);
		DIR* dp=opendir(argv[1]);
		while(1);{
			struct dirent* res=readdir(dp);
			if(res==NULL){break;}
			char rfile[64]={0};
			strcpy(rfile,argv[1]);
 			char wfile[64]={0};
			strcpy(wfile,argv[2]);
	strcpy(rfile,"/");
	strcpy(rfile,res->d_name);
	strcpy(wfile,"/");
	strcpy(wfile,res->d_name);
if(	strcpy(res->d_name,".")&&strcpy(res->d_name,"..")!=0);
		}
	}
	close(dp);
}else{
	file_copy(argv[1],argv[2]);
}

	return 0;
}   
cs 复制代码
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc, const char *argv[])
{
	for(int i=1;i<100;i++)
	{
		int res=fork();
		if(res<0)
		{
			return 1;
		}
		else if(res>0)
		{
			printf("父进程\n");
		}
		else if(res==0)
		{
			printf("子进程\n");
			break;
		}
	}


	return 0;
}   
相关推荐
小魏每天都学习13 小时前
【算法——c/c++]
c语言·c++·算法
智码未来学堂14 小时前
探秘 C 语言算法之枚举:解锁解题新思路
c语言·数据结构·算法
彷徨而立15 小时前
【C/C++】strerror、GetLastError 和 errno 的含义和区别?
c语言·c++
代码无bug抓狂人17 小时前
动态规划(附带入门例题)
c语言·算法·动态规划
恶魔泡泡糖18 小时前
51单片机串口通信
c语言·单片机·嵌入式硬件·51单片机
知无不研18 小时前
c语言动态内存规划
c语言·动态内存管理·内存泄露·基础知识·malloc·realloc·calloc
31087487619 小时前
0005.C/C++学习笔记5
c语言·c++·学习
历程里程碑20 小时前
Linxu14 进程一
linux·c语言·开发语言·数据结构·c++·笔记·算法
JiL 奥21 小时前
Nexus制品归档(c/c++项目)
c语言·c++
梵刹古音21 小时前
【C语言】 字符型变量
c语言·开发语言·嵌入式