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;
}   
相关推荐
呜喵王阿尔萨斯3 小时前
编程中的英语
c语言·c++
only-lucky4 小时前
C语言socket编程-补充
服务器·c语言·php
JeffersonZU5 小时前
Linux/Unix进程概念及基本操作(PID、内存布局、虚拟内存、环境变量、fork、exit、wait、exec、system)
linux·c语言·unix·gnu
ruanjiananquan997 小时前
c,c++语言的栈内存、堆内存及任意读写内存
java·c语言·c++
持梦远方7 小时前
C 语言基础入门:基本数据类型与运算符详解
c语言·开发语言·c++
Heartoxx7 小时前
c语言-指针(数组)练习2
c语言·数据结构·算法
码农不惑15 小时前
2025.06.27-14.44 C语言开发:Onvif(二)
c语言·开发语言
凌肖战17 小时前
力扣网C语言编程题:在数组中查找目标值位置之二分查找法
c语言·算法·leetcode
BreezeJuvenile17 小时前
数据结构与算法分析课设:一元多项式求值
c语言·课程设计·数据结构与算法分析·一元多项式计算