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;
}   
相关推荐
Y40900127 分钟前
C语言转Java语言,相同与相异之处
java·c语言·开发语言·笔记
棐木8 小时前
【C语言】动态内存管理
c语言·free·malloc·realloc·calloc·动态内存
屁股割了还要学13 小时前
【C语言进阶】内存函数
c语言·开发语言·学习·算法·青少年编程
耳总是一颗苹果13 小时前
C语言---自定义类型(上)(结构体类型)
c语言·开发语言
basketball61617 小时前
Linux C 进程基本操作
linux·运维·服务器·c语言·后端
草莓熊Lotso17 小时前
【LeetCode刷题指南】--数组串联,合并两个有序数组,删除有序数组中的重复项
c语言·数据结构·其他·刷题
平哥努力学习ing17 小时前
C语言内存函数
c语言·开发语言·算法
wenke00a18 小时前
C函数实现strcopy strcat strcmp strstr
c语言·前端
慕洋男孩19 小时前
错误经验一:计算两个整数a和b的和
c语言·经验分享·错误经验
小xiao白20 小时前
不能使用枚举作为 宏定义的定义
c语言·ide·单片机·物联网