#include <sys/stat.h>
#include<stdio.h>
#include<sys/types.h>
void main()
{
pid_t pid;
//创建新的进程
pid=fork();
int processID = getpid();
char strID[10],filename[100],cmd[200];
//如果返回0,则表示为子进程
if(0 == pid)
{
sprintf(filename, "tmp/%d", processID);
sprintf(cmd,"rm -r %s",filename);
if(access(filename,0)==0)//使用access函数查看文件夹是否存在,存在则删除原文件夹
{
//printf("file exists!!!");
system(cmd);
}
if (mkdir(filename,0777))//用mkdir函数来创建新文件夹
{
printf("creat file bag failed!");
}
FILE *fp;
sprintf(filename, "tmp/%d/hello.txt", processID);
if((fp=fopen(filename,"w"))==NULL)//创建文件hello.txt
{
printf("creat file failed!\n");
}
fprintf(fp,"hello,world!");
fclose(fp);
}
}#include <sys/stat.h>
#include<stdio.h>
#includ