Linux系统编程 进度%60

This commit is contained in:
clint 2025-07-14 01:38:46 +08:00
parent 378fec8ac9
commit 6de2de0331
19 changed files with 128 additions and 0 deletions

Binary file not shown.

View File

@ -0,0 +1,22 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
int main(int argc, char *argv[])
{
int ret;
if(argc !=2 )
{
printf("uage:%s <name file\n",argv[0]);
return -1;
}
ret = mkdir(argv[1],0666);
if(ret<0)
{
printf("mkdir is error\n");
}
printf("mkdir is ok\n");
return 0;
}

Binary file not shown.

View File

@ -0,0 +1,25 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
int main(int argc, char *argv[])
{
int ret;
DIR *dp;
if (argc !=2){
printf("Usage:%s <name file>\n", argv[0]);
return -1;
}
dp = opendir(argv[1]);
if (dp !=NULL){
printf("opendir is ok\n");
return -1;
}
closedir(dp);
printf("opendir is closed\n");
return 0;
}

Binary file not shown.

View File

@ -0,0 +1,32 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
int main(int argc, char *argv[])
{ int ret;
DIR *dp;
struct dirent *dir;
if (argc != 2){
printf("Uage:%s <name file>\n",argv[0]);
return -1;
};
dp = opendir(argv[1]);
if (dp == NULL) {
printf("opendir is error\n\n");
return -2;
}
printf("opendir is ok\n");
while(1)
{
dir = readdir(dp);
if (dir!=NULL) {
printf("file name is %s\n",dir->d_name);
}
else
break;
}
closedir(dp);
return 0;
}

View File

@ -0,0 +1,6 @@
#include <stdio.h>
void mylib(void);
void mylib(void)
{
printf("This is mylib\n");
}

View File

@ -0,0 +1,7 @@
#include <stdio.h>
void mylib(void);
int main(void){
mylib();
return 0;
}

View File

@ -0,0 +1,6 @@
#include <stdio.h>
void mylib(void);
void mylib(void)
{
printf("This is mylib\n");
}

View File

@ -0,0 +1,7 @@
#include <stdio.h>
void mylib(void);
int main(void){
mylib();
return 0;
}

Binary file not shown.

View File

@ -0,0 +1,23 @@
#include <stdio.h>
#include <unistd.h>
int main(void)
{
pid_t pid;
pid = fork();
if (pid < 0)
{
printf("fork is error\n");
return -1;
}
// 父进程
if (pid > 0) {
printf("This is parent, parent pid is %d\n",getppid());
}
// 子进程
if (pid == 0){
printf("This is child, child pid is %d\n",getpid());
}
return 0;
}