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;
}   
相关推荐
CQ_YM12 小时前
Linux线程控制
linux·c语言·开发语言·线程
lingran__12 小时前
C语言字符函数和字符串函数详解
c语言·开发语言
white-persist13 小时前
【攻防世界】reverse | simple-check-100 详细题解 WP
c语言·开发语言·汇编·数据结构·c++·python·算法
☆cwlulu14 小时前
C/C++ 内存分配函数详解
c语言·c++
程芯带你刷C语言简单算法题17 小时前
Day30~实现strcmp、strncmp、strchr、strpbrk
c语言·学习·算法·c
自然常数e18 小时前
深入理解指针(7)
c语言·数据结构·算法·visual studio
bocoder19 小时前
ESP-IDF(FreeRTOS)
c语言·单片机·嵌入式硬件
qs701620 小时前
c直接调用FFmpeg命令无法执行问题
c语言·开发语言·ffmpeg
福尔摩斯张20 小时前
【实战】C/C++ 实现 PC 热点(手动开启)+ 手机 UDP 自动发现 + TCP 通信全流程(超详细)
linux·c语言·c++·tcp/ip·算法·智能手机·udp