基础开发工具(中)

基础开发工具(中)

文章目录

4. 自动化构建-make/Makefile

自动化构建-make/Makefile
[gsm@VM-4-3-centos lesson7]$ touch proc.c [gsm@VM-4-3-centos lesson7]$ ll total 0-rw-rw-r--1 gsm gsm 0 Oct 1215:53 proc.c [gsm@VM-4-3-centos lesson7]$ vim proc.c [gsm@VM-4-3-centos lesson7]$ ll total 4-rw-rw-r--1 gsm gsm 79 Oct 1215:54 proc.c [gsm@VM-4-3-centos lesson7]$ gcc -o proc proc.c [gsm@VM-4-3-centos lesson7]$ ll total 16-rwxrwxr-x 1 gsm gsm 8360 Oct 1215:55 proc -rw-rw-r--1 gsm gsm 79 Oct 1215:54 proc.c [gsm@VM-4-3-centos lesson7]$ ./proc hello Linux![gsm@VM-4-3-centos lesson7]$ rm proc [gsm@VM-4-3-centos lesson7]$ ll total 4-rw-rw-r--1 gsm gsm 79 Oct 1215:54 proc.c [gsm@VM-4-3-centos lesson7]$ touch Makefile [gsm@VM-4-3-centos lesson7]$ ll total 4-rw-rw-r--1 gsm gsm 0 Oct 1215:56 Makefile -rw-rw-r--1 gsm gsm 79 Oct 1215:54 proc.c [gsm@VM-4-3-centos lesson7]$ vim Makefile [gsm@VM-4-3-centos lesson7]$ cat Makefile proc:proc.c gcc -o proc proc.c [gsm@VM-4-3-centos lesson7]$ ll total 8-rw-rw-r--1 gsm gsm 32 Oct 1215:58 Makefile -rw-rw-r--1 gsm gsm 79 Oct 1215:54 proc.c [gsm@VM-4-3-centos lesson7]$ make gcc -o proc proc.c [gsm@VM-4-3-centos lesson7]$ ll total 20-rw-rw-r--1 gsm gsm 32 Oct 1215:58 Makefile -rwxrwxr-x 1 gsm gsm 8360 Oct 1215:59 proc -rw-rw-r--1 gsm gsm 79 Oct 1215:54 proc.c [gsm@VM-4-3-centos lesson7]$ ./proc hello Linux![gsm@VM-4-3-centos lesson7]$ rm proc [gsm@VM-4-3-centos lesson7]$ ll total 8-rw-rw-r--1 gsm gsm 32 Oct 1215:58 Makefile -rw-rw-r--1 gsm gsm 79 Oct 1215:54 proc.c [gsm@VM-4-3-centos lesson7]$ vim Makefile [gsm@VM-4-3-centos lesson7]$ ll total 8-rw-rw-r--1 gsm gsm 64 Oct 1216:14 Makefile -rw-rw-r--1 gsm gsm 79 Oct 1215:54 proc.c [gsm@VM-4-3-centos lesson7]$ cat Makefile proc:proc.c gcc -o proc proc.c .PHONY:clean clean: rm -f proc [gsm@VM-4-3-centos lesson7]$ make gcc -o proc proc.c [gsm@VM-4-3-centos lesson7]$ ./proc hello Linux![gsm@VM-4-3-centos lesson7]$ ll total 20-rw-rw-r--1 gsm gsm 64 Oct 1216:14 Makefile -rwxrwxr-x 1 gsm gsm 8360 Oct 1216:15 proc -rw-rw-r--1 gsm gsm 79 Oct 1215:54 proc.c [gsm@VM-4-3-centos lesson7]$ make clean rm -f proc [gsm@VM-4-3-centos lesson7]$ ll total 8-rw-rw-r--1 gsm gsm 64 Oct 1216:14 Makefile -rw-rw-r--1 gsm gsm 79 Oct 1215:54 proc.c [gsm@VM-4-3-centos lesson7]$ make proc gcc -o proc proc.c [gsm@VM-4-3-centos lesson7]$ ll total 20-rw-rw-r--1 gsm gsm 64 Oct 1216:14 Makefile -rwxrwxr-x 1 gsm gsm 8360 Oct 1216:22 proc -rw-rw-r--1 gsm gsm 79 Oct 1215:54 proc.c [gsm@VM-4-3-centos lesson7]$ make clean rm -f proc [gsm@VM-4-3-centos lesson7]$ ll total 8-rw-rw-r--1 gsm gsm 64 Oct 1216:14 Makefile -rw-rw-r--1 gsm gsm 79 Oct 1215:54 proc.c [gsm@VM-4-3-centos lesson7]$ vim Makefile [gsm@VM-4-3-centos lesson7]$ cat Makefile .PHONY:clean clean: rm -f proc proc:proc.c gcc -o proc proc.c [gsm@VM-4-3-centos lesson7]$ make rm -f proc [gsm@VM-4-3-centos lesson7]$ make proc gcc -o proc proc.c [gsm@VM-4-3-centos lesson7]$ ll total 20-rw-rw-r--1 gsm gsm 64 Oct 1216:24 Makefile -rwxrwxr-x 1 gsm gsm 8360 Oct 1216:24 proc -rw-rw-r--1 gsm gsm 79 Oct 1215:54 proc.c [gsm@VM-4-3-centos lesson7]$ vim Makefile [gsm@VM-4-3-centos lesson7]$ vim Makefile [gsm@VM-4-3-centos lesson7]$ ll total 20-rw-rw-r--1 gsm gsm 94 Oct 1216:27 Makefile -rwxrwxr-x 1 gsm gsm 8360 Oct 1216:24 proc -rw-rw-r--1 gsm gsm 79 Oct 1215:54 proc.c [gsm@VM-4-3-centos lesson7]$ rm proc [gsm@VM-4-3-centos lesson7]$ ll total 8-rw-rw-r--1 gsm gsm 94 Oct 1216:27 Makefile -rw-rw-r--1 gsm gsm 79 Oct 1215:54 proc.c [gsm@VM-4-3-centos lesson7]$ cat Makefile proc:proc.c echo "hahaha"#gcc-o proc proc.c.PHONY:clean clean: echo "hehe"#rm-f proc[gsm@VM-4-3-centos lesson7]$ make echo "hahaha" hahaha #gcc-o proc proc.c[gsm@VM-4-3-centos lesson7]$ vim Makefile [gsm@VM-4-3-centos lesson7]$ cat Makefile proc:proc.c echo "hahaha".PHONY:clean clean: echo "hehe"#rm-f proc[gsm@VM-4-3-centos lesson7]$ make echo "hahaha" hahaha [gsm@VM-4-3-centos lesson7]$ ll total 8-rw-rw-r--1 gsm gsm 73 Oct 1216:29 Makefile -rw-rw-r--1 gsm gsm 79 Oct 1215:54 proc.c [gsm@VM-4-3-centos lesson7]$ vim Makefile [gsm@VM-4-3-centos lesson7]$ make echo "hahaha" hahaha echo "hahaha" hahaha echo "hahaha" hahaha echo "hahaha" hahaha [gsm@VM-4-3-centos lesson7]$ vim Makefile [gsm@VM-4-3-centos lesson7]$ cat Makefile proc:proc.c @echo "hahaha" @echo "hahaha" @echo "hahaha" @echo "hahaha".PHONY:clean clean: echo "hehe"#rm-f proc[gsm@VM-4-3-centos lesson7]$ make hahaha hahaha hahaha hahaha [gsm@VM-4-3-centos lesson7]$ vim Makefile [gsm@VM-4-3-centos lesson7]$ cat Makefile proc:proc.c @echo "开始编译..." @gcc -o proc proc.c @echo "结束编译...".PHONY:clean clean: @echo "清理完成..." @rm -f proc [gsm@VM-4-3-centos lesson7]$ make 开始编译... 结束编译...[gsm@VM-4-3-centos lesson7]$ vim proc.c [gsm@VM-4-3-centos lesson7]$ cat proc.c #include<stdio.h>intmain(){printf("hello Linux!\n")return0;}[gsm@VM-4-3-centos lesson7]$ make clean 清理完成...[gsm@VM-4-3-centos lesson7]$ make 开始编译... proc.c: In function ‘main’: proc.c:6:5: error: expected ‘;’ before ‘return’ return0;^ make:***[proc] Error 1[gsm@VM-4-3-centos lesson7]$ vim proc.c [gsm@VM-4-3-centos lesson7]$ ll total 8-rw-rw-r--1 gsm gsm 141 Oct 1216:35 Makefile -rw-rw-r--1 gsm gsm 79 Oct 1216:39 proc.c [gsm@VM-4-3-centos lesson7]$ make 开始编译... 结束编译...[gsm@VM-4-3-centos lesson7]$ ll total 20-rw-rw-r--1 gsm gsm 141 Oct 1216:35 Makefile -rwxrwxr-x 1 gsm gsm 8360 Oct 1216:39 proc -rw-rw-r--1 gsm gsm 79 Oct 1216:39 proc.c [gsm@VM-4-3-centos lesson7]$ ./proc hello Linux![gsm@VM-4-3-centos lesson7]$ make clean 清理完成...[gsm@VM-4-3-centos lesson7]$ ll total 8-rw-rw-r--1 gsm gsm 141 Oct 1216:35 Makefile -rw-rw-r--1 gsm gsm 79 Oct 1216:39 proc.c [gsm@VM-4-3-centos lesson7]$ cp Makefile backup1012 [gsm@VM-4-3-centos lesson7]$ ll total 12-rw-rw-r--1 gsm gsm 141 Oct 1216:41 backup1012 -rw-rw-r--1 gsm gsm 141 Oct 1216:35 Makefile -rw-rw-r--1 gsm gsm 79 Oct 1216:39 proc.c [gsm@VM-4-3-centos lesson7]$ vim Makefile [gsm@VM-4-3-centos lesson7]$ cat Makefile proc:proc.c gcc -o proc proc.c .PHONY:clean clean: rm -f proc [gsm@VM-4-3-centos lesson7]$ make gcc -o proc proc.c [gsm@VM-4-3-centos lesson7]$ ll total 24-rw-rw-r--1 gsm gsm 141 Oct 1216:41 backup1012 -rw-rw-r--1 gsm gsm 64 Oct 1216:42 Makefile -rwxrwxr-x 1 gsm gsm 8360 Oct 1216:42 proc -rw-rw-r--1 gsm gsm 79 Oct 1216:39 proc.c [gsm@VM-4-3-centos lesson7]$ ./proc hello Linux![gsm@VM-4-3-centos lesson7]$ mv backup1012 ..[gsm@VM-4-3-centos lesson7]$ ll total 20-rw-rw-r--1 gsm gsm 64 Oct 1216:42 Makefile -rwxrwxr-x 1 gsm gsm 8360 Oct 1216:42 proc -rw-rw-r--1 gsm gsm 79 Oct 1216:39 proc.c [gsm@VM-4-3-centos lesson7]$ make clean rm -f proc [gsm@VM-4-3-centos lesson7]$ ll total 8-rw-rw-r--1 gsm gsm 64 Oct 1216:42 Makefile -rw-rw-r--1 gsm gsm 79 Oct 1216:39 proc.c [gsm@VM-4-3-centos lesson7]$ make gcc -o proc proc.c [gsm@VM-4-3-centos lesson7]$ ./proc hello Linux![gsm@VM-4-3-centos lesson7]$ ll total 20-rw-rw-r--1 gsm gsm 64 Oct 1216:48 Makefile -rwxrwxr-x 1 gsm gsm 8360 Oct 1216:49 proc -rw-rw-r--1 gsm gsm 79 Oct 1216:39 proc.c [gsm@VM-4-3-centos lesson7]$ make make: `proc' is up to date.[gsm@VM-4-3-centos lesson7]$ vim Makefile [gsm@VM-4-3-centos lesson7]$ cat Makefile proc:proc.c gcc -o proc proc.c #.PHONY:clean clean: rm -f proc [gsm@VM-4-3-centos lesson7]$ make clean rm -f proc [gsm@VM-4-3-centos lesson7]$ make gcc -o proc proc.c [gsm@VM-4-3-centos lesson7]$ make make: `proc' is up to date.[gsm@VM-4-3-centos lesson7]$ make make: `proc' is up to date.[gsm@VM-4-3-centos lesson7]$ make clean rm -f proc [gsm@VM-4-3-centos lesson7]$ make clean rm -f proc [gsm@VM-4-3-centos lesson7]$ make clean rm -f proc [gsm@VM-4-3-centos lesson7]$ vim Makefile [gsm@VM-4-3-centos lesson7]$ cat Makefile .PHONY:proc proc:proc.c gcc -o proc proc.c #.PHONY:clean clean: rm -f proc [gsm@VM-4-3-centos lesson7]$ make clean rm -f proc [gsm@VM-4-3-centos lesson7]$ make gcc -o proc proc.c [gsm@VM-4-3-centos lesson7]$ ./proc hello Linux![gsm@VM-4-3-centos lesson7]$ make gcc -o proc proc.c [gsm@VM-4-3-centos lesson7]$ make gcc -o proc proc.c [gsm@VM-4-3-centos lesson7]$ make gcc -o proc proc.c [gsm@VM-4-3-centos lesson7]$ ll total 20-rw-rw-r--1 gsm gsm 78 Oct 1217:00 Makefile -rwxrwxr-x 1 gsm gsm 8360 Oct 1217:01 proc -rw-rw-r--1 gsm gsm 79 Oct 1216:39 proc.c [gsm@VM-4-3-centos lesson7]$ make clean rm -f proc [gsm@VM-4-3-centos lesson7]$ ll total 8-rw-rw-r--1 gsm gsm 78 Oct 1217:00 Makefile -rw-rw-r--1 gsm gsm 79 Oct 1216:39 proc.c [gsm@VM-4-3-centos lesson7]$ vim Makefile [gsm@VM-4-3-centos lesson7]$ cat Makefile #.PHONY:proc proc:proc.c gcc -o proc proc.c #.PHONY:clean clean: rm -f proc [gsm@VM-4-3-centos lesson7]$ make gcc -o proc proc.c [gsm@VM-4-3-centos lesson7]$ ll total 20-rw-rw-r--1 gsm gsm 79 Oct 1217:06 Makefile -rwxrwxr-x 1 gsm gsm 8360 Oct 1217:06 proc -rw-rw-r--1 gsm gsm 79 Oct 1216:39 proc.c [gsm@VM-4-3-centos lesson7]$ ./proc hello Linux![gsm@VM-4-3-centos lesson7]$ make make: `proc' is up to date.[gsm@VM-4-3-centos lesson7]$ make make: `proc' is up to date.[gsm@VM-4-3-centos lesson7]$ vim proc.c [gsm@VM-4-3-centos lesson7]$ cat proc.c #include<stdio.h>intmain(){printf("hello Linux!\n");printf("hello Linux!\n");printf("hello Linux!\n");printf("hello Linux!\n");return0;}[gsm@VM-4-3-centos lesson7]$ make gcc -o proc proc.c [gsm@VM-4-3-centos lesson7]$ make make: `proc' is up to date.[gsm@VM-4-3-centos lesson7]$ ll total 20-rw-rw-r--1 gsm gsm 79 Oct 1217:06 Makefile -rwxrwxr-x 1 gsm gsm 8360 Oct 1217:07 proc -rw-rw-r--1 gsm gsm 169 Oct 1217:07 proc.c [gsm@VM-4-3-centos lesson7]$ stat proc.c File: ‘proc.c’ Size:169 Blocks:8 IO Block:4096 regular file Device: fd01h/64769d Inode:1052393 Links:1 Access:(0664/-rw-rw-r--) Uid:(1001/ gsm) Gid:(1001/ gsm) Access:2025-10-1217:07:11.741037892+0800 Modify:2025-10-1217:07:11.739037901+0800 Change:2025-10-1217:07:11.739037901+0800 Birth:-[gsm@VM-4-3-centos lesson7]$ ll total 20-rw-rw-r--1 gsm gsm 79 Oct 1217:06 Makefile -rwxrwxr-x 1 gsm gsm 8360 Oct 1217:07 proc -rw-rw-r--1 gsm gsm 169 Oct 1217:07 proc.c [gsm@VM-4-3-centos lesson7]$ chmod o-r proc.c [gsm@VM-4-3-centos lesson7]$ ll total 20-rw-rw-r--1 gsm gsm 79 Oct 1217:06 Makefile -rwxrwxr-x 1 gsm gsm 8360 Oct 1217:07 proc -rw-rw----1 gsm gsm 169 Oct 1217:07 proc.c [gsm@VM-4-3-centos lesson7]$ stat proc.c File: ‘proc.c’ Size:169 Blocks:8 IO Block:4096 regular file Device: fd01h/64769d Inode:1052393 Links:1 Access:(0660/-rw-rw----) Uid:(1001/ gsm) Gid:(1001/ gsm) Access:2025-10-1217:07:11.741037892+0800 Modify:2025-10-1217:07:11.739037901+0800 Change:2025-10-1217:14:13.525097070+0800 Birth:-[gsm@VM-4-3-centos lesson7]$ vim proc.c [gsm@VM-4-3-centos lesson7]$ cat proc.c #include<stdio.h>intmain(){printf("hello Linux!\n");printf("hello Linux!\n");printf("hello Linux!\n");printf("hello Linux!\n");printf("hello Linux!\n");printf("hello Linux!\n");printf("hello Linux!\n");return0;}[gsm@VM-4-3-centos lesson7]$ stat proc.c File: ‘proc.c’ Size:259 Blocks:8 IO Block:4096 regular file Device: fd01h/64769d Inode:1052393 Links:1 Access:(0660/-rw-rw----) Uid:(1001/ gsm) Gid:(1001/ gsm) Access:2025-10-1217:15:26.229763190+0800 Modify:2025-10-1217:15:26.226763204+0800 Change:2025-10-1217:15:26.226763204+0800 Birth:-[gsm@VM-4-3-centos lesson7]$ ll total 20-rw-rw-r--1 gsm gsm 79 Oct 1217:06 Makefile -rwxrwxr-x 1 gsm gsm 8360 Oct 1217:07 proc -rw-rw----1 gsm gsm 259 Oct 1217:15 proc.c [gsm@VM-4-3-centos lesson7]$ make gcc -o proc proc.c [gsm@VM-4-3-centos lesson7]$ make make: `proc' is up to date.[gsm@VM-4-3-centos lesson7]$ make make: `proc' is up to date.[gsm@VM-4-3-centos lesson7]$ stat proc.c File: ‘proc.c’ Size:259 Blocks:8 IO Block:4096 regular file Device: fd01h/64769d Inode:1052393 Links:1 Access:(0660/-rw-rw----) Uid:(1001/ gsm) Gid:(1001/ gsm) Access:2025-10-1217:15:26.229763190+0800 Modify:2025-10-1217:15:26.226763204+0800 Change:2025-10-1217:15:26.226763204+0800 Birth:-[gsm@VM-4-3-centos lesson7]$ stat proc File: ‘proc’ Size:8360 Blocks:24 IO Block:4096 regular file Device: fd01h/64769d Inode:1052395 Links:1 Access:(0775/-rwxrwxr-x) Uid:(1001/ gsm) Gid:(1001/ gsm) Access:2025-10-1217:23:44.872478158+0800 Modify:2025-10-1217:23:44.147481475+0800 Change:2025-10-1217:23:44.147481475+0800 Birth:-[gsm@VM-4-3-centos lesson7]$ make make: `proc' is up to date.[gsm@VM-4-3-centos lesson7]$ touch -m proc.c [gsm@VM-4-3-centos lesson7]$ stat proc.c File: ‘proc.c’ Size:259 Blocks:8 IO Block:4096 regular file Device: fd01h/64769d Inode:1052393 Links:1 Access:(0660/-rw-rw----) Uid:(1001/ gsm) Gid:(1001/ gsm) Access:2025-10-1217:25:46.871920321+0800 Modify:2025-10-1217:25:45.957924498+0800 Change:2025-10-1217:25:45.957924498+0800 Birth:-[gsm@VM-4-3-centos lesson7]$ make gcc -o proc proc.c [gsm@VM-4-3-centos lesson7]$ stat proc File: ‘proc’ Size:8360 Blocks:24 IO Block:4096 regular file Device: fd01h/64769d Inode:1052395 Links:1 Access:(0775/-rwxrwxr-x) Uid:(1001/ gsm) Gid:(1001/ gsm) Access:2025-10-1217:26:32.865710134+0800 Modify:2025-10-1217:26:32.422712158+0800 Change:2025-10-1217:26:32.422712158+0800 Birth:-[gsm@VM-4-3-centos lesson7]$ make make: `proc' is up to date.[gsm@VM-4-3-centos lesson7]$ touch proc.c [gsm@VM-4-3-centos lesson7]$ stat proc.c File: ‘proc.c’ Size:259 Blocks:8 IO Block:4096 regular file Device: fd01h/64769d Inode:1052393 Links:1 Access:(0660/-rw-rw----) Uid:(1001/ gsm) Gid:(1001/ gsm) Access:2025-10-1217:27:22.865481713+0800 Modify:2025-10-1217:27:21.185489386+0800 Change:2025-10-1217:27:21.185489386+0800 Birth:-[gsm@VM-4-3-centos lesson7]$ make gcc -o proc proc.c [gsm@VM-4-3-centos lesson7]$ ll total 20-rw-rw-r--1 gsm gsm 79 Oct 1217:06 Makefile -rwxrwxr-x 1 gsm gsm 8360 Oct 1217:27 proc -rw-rw----1 gsm gsm 259 Oct 1217:27 proc.c [gsm@VM-4-3-centos lesson7]$ vim Makefile [gsm@VM-4-3-centos lesson7]$ cat Makefile .PHONY:proc proc:proc.c gcc -o proc proc.c #.PHONY:clean clean: rm -f proc [gsm@VM-4-3-centos lesson7]$ make gcc -o proc proc.c [gsm@VM-4-3-centos lesson7]$ make gcc -o proc proc.c [gsm@VM-4-3-centos lesson7]$ make gcc -o proc proc.c [gsm@VM-4-3-centos lesson7]$ make clean rm -f proc [gsm@VM-4-3-centos lesson7]$ ll total 8-rw-rw-r--1 gsm gsm 78 Oct 1217:30 Makefile -rw-rw----1 gsm gsm 259 Oct 1217:27 proc.c [gsm@VM-4-3-centos lesson7]$ vim Makefile [gsm@VM-4-3-centos lesson7]$ cat Makefile proc:proc.c gcc -o proc proc.c .PHONY:clean clean: rm -f proc [gsm@VM-4-3-centos lesson7]$ ll total 8-rw-rw-r--1 gsm gsm 65 Oct 1217:56 Makefile -rw-rw----1 gsm gsm 259 Oct 1217:27 proc.c [gsm@VM-4-3-centos lesson7]$ cp Makefile backup20251012_2 [gsm@VM-4-3-centos lesson7]$ ll total 12-rw-rw-r--1 gsm gsm 65 Oct 1217:57 backup20251012_2 -rw-rw-r--1 gsm gsm 65 Oct 1217:56 Makefile -rw-rw----1 gsm gsm 259 Oct 1217:27 proc.c [gsm@VM-4-3-centos lesson7]$ mv backup20251012_2 ..[gsm@VM-4-3-centos lesson7]$ ll total 8-rw-rw-r--1 gsm gsm 65 Oct 1217:56 Makefile -rw-rw----1 gsm gsm 259 Oct 1217:27 proc.c [gsm@VM-4-3-centos lesson7]$ vim Makefile [gsm@VM-4-3-centos lesson7]$ cat Makefile proc:proc.o gcc proc.o -o proc proc.o:proc.s gcc -c proc.s -o proc.o proc.s:proc.i gcc -S proc.i -o proc.s proc.i:proc.c gcc -E proc.c -o proc.i .PHONY:clean clean: rm -f proc [gsm@VM-4-3-centos lesson7]$ make gcc -E proc.c -o proc.i gcc -S proc.i -o proc.s gcc -c proc.s -o proc.o gcc proc.o -o proc [gsm@VM-4-3-centos lesson7]$ ll total 48-rw-rw-r--1 gsm gsm 183 Oct 1218:05 Makefile -rwxrwxr-x 1 gsm gsm 8360 Oct 1218:05 proc -rw-rw----1 gsm gsm 259 Oct 1217:27 proc.c -rw-rw-r--1 gsm gsm 17057 Oct 1218:05 proc.i -rw-rw-r--1 gsm gsm 1848 Oct 1218:05 proc.o -rw-rw-r--1 gsm gsm 622 Oct 1218:05 proc.s [gsm@VM-4-3-centos lesson7]$ ./proc hello Linux! hello Linux! hello Linux! hello Linux! hello Linux! hello Linux! hello Linux![gsm@VM-4-3-centos lesson7]$ vim Makefile [gsm@VM-4-3-centos lesson7]$ cat Makefile proc:proc.o gcc proc.o -o proc proc.o:proc.s gcc -c proc.s -o proc.o proc.s:proc.i gcc -S proc.i -o proc.s proc.i:proc.c gcc -E proc.c -o proc.i .PHONY:clean clean: rm -f proc.i proc.s proc.o proc [gsm@VM-4-3-centos lesson7]$ make clean rm -f proc.i proc.s proc.o proc [gsm@VM-4-3-centos lesson7]$ ll total 8-rw-rw-r--1 gsm gsm 204 Oct 1218:07 Makefile -rw-rw----1 gsm gsm 259 Oct 1217:27 proc.c [gsm@VM-4-3-centos lesson7]$ vim Makefile [gsm@VM-4-3-centos lesson7]$ cat Makefile proc:proc.o gcc proc.o -o proc proc.o:proc.c gcc -c proc.c .PHONY:clean clean: rm -f proc.o proc [gsm@VM-4-3-centos lesson7]$ ll total 8-rw-rw-r--1 gsm gsm 102 Oct 1218:17 Makefile -rw-rw----1 gsm gsm 259 Oct 1217:27 proc.c [gsm@VM-4-3-centos lesson7]$ make gcc -c proc.c gcc proc.o -o proc [gsm@VM-4-3-centos lesson7]$ ll total 24-rw-rw-r--1 gsm gsm 102 Oct 1218:17 Makefile -rwxrwxr-x 1 gsm gsm 8360 Oct 1218:17 proc -rw-rw----1 gsm gsm 259 Oct 1217:27 proc.c -rw-rw-r--1 gsm gsm 1848 Oct 1218:17 proc.o [gsm@VM-4-3-centos lesson7]$ make clean rm -f proc.o proc [gsm@VM-4-3-centos lesson7]$ ll total 8-rw-rw-r--1 gsm gsm 102 Oct 1218:17 Makefile -rw-rw----1 gsm gsm 259 Oct 1217:27 proc.c [gsm@VM-4-3-centos lesson7]$ vim Makefile [gsm@VM-4-3-centos lesson7]$ cat Makefile proc:proc.o gcc proc.o -o proc %.o:%.c gcc -c $<.PHONY:clean clean: rm -f proc.o proc [gsm@VM-4-3-centos lesson7]$ make gcc -c proc.c gcc proc.o -o proc [gsm@VM-4-3-centos lesson7]$ ll total 24-rw-rw-r--1 gsm gsm 92 Oct 1218:20 Makefile -rwxrwxr-x 1 gsm gsm 8360 Oct 1218:22 proc -rw-rw----1 gsm gsm 259 Oct 1217:27 proc.c -rw-rw-r--1 gsm gsm 1848 Oct 1218:22 proc.o [gsm@VM-4-3-centos lesson7]$ make clean rm -f proc.o proc [gsm@VM-4-3-centos lesson7]$ ll total 8-rw-rw-r--1 gsm gsm 92 Oct 1218:20 Makefile -rw-rw----1 gsm gsm 259 Oct 1217:27 proc.c [gsm@VM-4-3-centos lesson7]$ vim Makefile [gsm@VM-4-3-centos lesson7]$ cat Makefile bin=proc src=proc.o $(bin):$(src) gcc $^-o $@ %.o:%.c gcc -c $<.PHONY:clean clean: rm -f proc.o $(bin)[gsm@VM-4-3-centos lesson7]$ make gcc -c proc.c gcc proc.o -o proc [gsm@VM-4-3-centos lesson7]$ ll total 24-rw-rw-r--1 gsm gsm 111 Oct 1219:47 Makefile -rwxrwxr-x 1 gsm gsm 8360 Oct 1219:47 proc -rw-rw----1 gsm gsm 259 Oct 1217:27 proc.c -rw-rw-r--1 gsm gsm 1848 Oct 1219:47 proc.o [gsm@VM-4-3-centos lesson7]$ ./proc hello Linux! hello Linux! hello Linux! hello Linux! hello Linux! hello Linux! hello Linux![gsm@VM-4-3-centos lesson7]$ make clean rm -f proc.o proc [gsm@VM-4-3-centos lesson7]$ ll total 8-rw-rw-r--1 gsm gsm 111 Oct 1219:47 Makefile -rw-rw----1 gsm gsm 259 Oct 1217:27 proc.c [gsm@VM-4-3-centos lesson7]$ cat Makefile bin=hello src=proc.o $(bin):$(src) gcc $^-o $@ %.o:%.c gcc -c $<.PHONY:clean clean: rm -f proc.o $(bin)[gsm@VM-4-3-centos lesson7]$ make gcc -c proc.c gcc proc.o -o hello [gsm@VM-4-3-centos lesson7]$ ll total 24-rwxrwxr-x 1 gsm gsm 8360 Oct 1219:48 hello -rw-rw-r--1 gsm gsm 112 Oct 1219:48 Makefile -rw-rw----1 gsm gsm 259 Oct 1217:27 proc.c -rw-rw-r--1 gsm gsm 1848 Oct 1219:48 proc.o [gsm@VM-4-3-centos lesson7]$ ./hello hello Linux! hello Linux! hello Linux! hello Linux! hello Linux! hello Linux! hello Linux![gsm@VM-4-3-centos lesson7]$ make clean rm -f proc.o hello [gsm@VM-4-3-centos lesson7]$ ll total 8-rw-rw-r--1 gsm gsm 112 Oct 1219:48 Makefile -rw-rw----1 gsm gsm 259 Oct 1217:27 proc.c [gsm@VM-4-3-centos lesson7]$ cp Makefile backup20251012_2 [gsm@VM-4-3-centos lesson7]$ ll total 12-rw-rw-r--1 gsm gsm 112 Oct 1219:50 backup20251012_2 -rw-rw-r--1 gsm gsm 112 Oct 1219:48 Makefile -rw-rw----1 gsm gsm 259 Oct 1217:27 proc.c [gsm@VM-4-3-centos lesson7]$ mv backup20251012_2 ..[gsm@VM-4-3-centos lesson7]$ ll total 8-rw-rw-r--1 gsm gsm 112 Oct 1219:48 Makefile -rw-rw----1 gsm gsm 259 Oct 1217:27 proc.c [gsm@VM-4-3-centos lesson7]$ vim Makefile [gsm@VM-4-3-centos lesson7]$ cat Makefile bin=proc src=proc.c $(bin):$(src) gcc $^-o $@ .PHONY:clean clean: rm -f $(bin)[gsm@VM-4-3-centos lesson7]$ make gcc proc.c -o proc [gsm@VM-4-3-centos lesson7]$ ll total 20-rw-rw-r--1 gsm gsm 84 Oct 1220:06 Makefile -rwxrwxr-x 1 gsm gsm 8360 Oct 1220:07 proc -rw-rw----1 gsm gsm 259 Oct 1217:27 proc.c [gsm@VM-4-3-centos lesson7]$ make clean rm -f proc [gsm@VM-4-3-centos lesson7]$ ll total 8-rw-rw-r--1 gsm gsm 84 Oct 1220:06 Makefile -rw-rw----1 gsm gsm 259 Oct 1217:27 proc.c [gsm@VM-4-3-centos lesson7]$ touch code.c [gsm@VM-4-3-centos lesson7]$ ll total 8-rw-rw-r--1 gsm gsm 0 Oct 1220:13 code.c -rw-rw-r--1 gsm gsm 84 Oct 1220:06 Makefile -rw-rw----1 gsm gsm 259 Oct 1217:27 proc.c [gsm@VM-4-3-centos lesson7]$ cat proc.c > code.c [gsm@VM-4-3-centos lesson7]$ vim code.c [gsm@VM-4-3-centos lesson7]$ cat proc.c #include<stdio.h>intmain(){printf("hello Linux!\n");printf("hello Linux!\n");printf("hello Linux!\n");printf("hello Linux!\n");printf("hello Linux!\n");printf("hello Linux!\n");printf("hello Linux!\n");return0;}[gsm@VM-4-3-centos lesson7]$ cat code.c #include<stdio.h>intmain(){printf("hello code!\n");printf("hello code!\n");printf("hello code!\n");printf("hello code!\n");printf("hello code!\n");printf("hello code!\n");return0;}[gsm@VM-4-3-centos lesson7]$ ll total 12-rw-rw-r--1 gsm gsm 223 Oct 1220:15 code.c -rw-rw-r--1 gsm gsm 84 Oct 1220:06 Makefile -rw-rw----1 gsm gsm 259 Oct 1217:27 proc.c [gsm@VM-4-3-centos lesson7]$ vim Makefile [gsm@VM-4-3-centos lesson7]$ cat Makefile bin1=proc src1=proc.c bin2=code src2=code.c .PHONY:all all:$(bin1) $(bin2) $(bin1):$(src1) gcc $^-o $@ $(bin2):$(src2) gcc $^-o $@ .PHONY:clean clean: rm -f $(bin1) $(bin2)[gsm@VM-4-3-centos lesson7]$ make gcc proc.c -o proc gcc code.c -o code [gsm@VM-4-3-centos lesson7]$ ll total 36-rwxrwxr-x 1 gsm gsm 8360 Oct 1220:28 code -rw-rw-r--1 gsm gsm 223 Oct 1220:15 code.c -rw-rw-r--1 gsm gsm 184 Oct 1220:28 Makefile -rwxrwxr-x 1 gsm gsm 8360 Oct 1220:28 proc -rw-rw----1 gsm gsm 259 Oct 1217:27 proc.c [gsm@VM-4-3-centos lesson7]$ ./proc hello Linux! hello Linux! hello Linux! hello Linux! hello Linux! hello Linux! hello Linux![gsm@VM-4-3-centos lesson7]$ ./code hello code! hello code! hello code! hello code! hello code! hello code![gsm@VM-4-3-centos lesson7]$ make clean rm -f proc code [gsm@VM-4-3-centos lesson7]$ ll total 12-rw-rw-r--1 gsm gsm 223 Oct 1220:15 code.c -rw-rw-r--1 gsm gsm 184 Oct 1220:28 Makefile -rw-rw----1 gsm gsm 259 Oct 1217:27 proc.c 

5. Linux第一个系统程序−进度条

Linux第一个系统程序−进度条
[gsm@VM-4-3-centos lesson7]$ ll total 12-rw-rw-r--1 gsm gsm 223 Oct 1220:15 code.c -rw-rw-r--1 gsm gsm 184 Oct 1220:28 Makefile -rw-rw----1 gsm gsm 259 Oct 1217:27 proc.c [gsm@VM-4-3-centos lesson7]$ vim proc.c [gsm@VM-4-3-centos lesson7]$ cat proc.c #include<stdio.h>#include<unistd.h>intmain(){printf("hello Linux!\n");sleep(2);return0;}[gsm@VM-4-3-centos lesson7]$ man 3 sleep [gsm@VM-4-3-centos lesson7]$ vim Makefile [gsm@VM-4-3-centos lesson7]$ cat Makefile bin1=proc src1=proc.c #bin2=code#src2=code.c #.PHONY:all #all:$(bin1) $(bin2) $(bin1):$(src1) gcc $^-o $@ #$(bin2):$(src2)#gcc$^-o [email protected]:clean clean: rm -f $(bin1)#rm-f $(bin1) $(bin2)[gsm@VM-4-3-centos lesson7]$ make gcc proc.c -o proc [gsm@VM-4-3-centos lesson7]$ ./proc hello Linux![gsm@VM-4-3-centos lesson7]$ vim proc.c [gsm@VM-4-3-centos lesson7]$ cat proc.c #include<stdio.h>#include<unistd.h>intmain(){printf("hello Linux!");sleep(2);return0;}[gsm@VM-4-3-centos lesson7]$ make gcc proc.c -o proc [gsm@VM-4-3-centos lesson7]$ ./proc hello Linux![gsm@VM-4-3-centos lesson7]$ man fflush [gsm@VM-4-3-centos lesson7]$ man stdin[gsm@VM-4-3-centos lesson7]$ ll total 24-rw-rw-r--1 gsm gsm 223 Oct 1220:15 code.c -rw-rw-r--1 gsm gsm 206 Oct 1221:01 Makefile -rwxrwxr-x 1 gsm gsm 8408 Oct 1221:03 proc -rw-rw----1 gsm gsm 112 Oct 1221:03 proc.c [gsm@VM-4-3-centos lesson7]$ vim proc.c [gsm@VM-4-3-centos lesson7]$ cat proc.c #include<stdio.h>#include<unistd.h>intmain(){printf("hello Linux!");fflush(stdout);sleep(2);return0;}[gsm@VM-4-3-centos lesson7]$ make gcc proc.c -o proc [gsm@VM-4-3-centos lesson7]$ ./proc hello Linux![gsm@VM-4-3-centos lesson7]$ make clean rm -f proc #rm-f proc [gsm@VM-4-3-centos lesson7]$ ll total 12-rw-rw-r--1 gsm gsm 223 Oct 1220:15 code.c -rw-rw-r--1 gsm gsm 206 Oct 1221:01 Makefile -rw-rw----1 gsm gsm 131 Oct 1221:29 proc.c 
[gsm@VM-4-3-centos lesson7]$ mkdir count [gsm@VM-4-3-centos lesson7]$ ll total 16-rw-rw-r--1 gsm gsm 223 Oct 1220:15 code.c drwxrwxr-x 2 gsm gsm 4096 Oct 1221:32 count -rw-rw-r--1 gsm gsm 206 Oct 1221:01 Makefile -rw-rw----1 gsm gsm 131 Oct 1221:29 proc.c [gsm@VM-4-3-centos lesson7]$ cd count/[gsm@VM-4-3-centos count]$ ll total 0[gsm@VM-4-3-centos count]$ touch Count.c [gsm@VM-4-3-centos count]$ ll total 0-rw-rw-r--1 gsm gsm 0 Oct 1221:33 Count.c [gsm@VM-4-3-centos count]$ ls > Makefile [gsm@VM-4-3-centos count]$ ll total 4-rw-rw-r--1 gsm gsm 0 Oct 1221:33 Count.c -rw-rw-r--1 gsm gsm 17 Oct 1221:33 Makefile [gsm@VM-4-3-centos count]$ vim Makefile [gsm@VM-4-3-centos count]$ ll total 4-rw-rw-r--1 gsm gsm 0 Oct 1221:33 Count.c -rw-rw-r--1 gsm gsm 61 Oct 1221:36 Makefile [gsm@VM-4-3-centos count]$ cat Makefile Count:Count.c gcc -o $@ $^.PHONY:clean clean: rm -f Count [gsm@VM-4-3-centos count]$ vim Count.c [gsm@VM-4-3-centos count]$ cat Count.c #include<stdio.h>#include<unistd.h>intmain(){int count =9;while(count >=0){printf("%d\n", count); count--;sleep(1);}return0;}[gsm@VM-4-3-centos count]$ make gcc -o Count Count.c [gsm@VM-4-3-centos count]$ ll total 20-rwxrwxr-x 1 gsm gsm 8408 Oct 1221:41 Count -rw-rw-r--1 gsm gsm 199 Oct 1221:40 Count.c -rw-rw-r--1 gsm gsm 61 Oct 1221:36 Makefile [gsm@VM-4-3-centos count]$ ./Count 9876543210[gsm@VM-4-3-centos count]$ make clean rm -f Count [gsm@VM-4-3-centos count]$ ll total 8-rw-rw-r--1 gsm gsm 199 Oct 1221:40 Count.c -rw-rw-r--1 gsm gsm 61 Oct 1221:36 Makefile [gsm@VM-4-3-centos count]$ vim Count.c [gsm@VM-4-3-centos count]$ cat Count.c #include<stdio.h>#include<unistd.h>intmain(){int count =9;while(count >=0){printf("%d\r", count);// \r回车,但是没有换行,也就没有刷新fflush(stdout); count--;sleep(1);}printf("\r\n");return0;}[gsm@VM-4-3-centos count]$ make gcc -o Count Count.c [gsm@VM-4-3-centos count]$ ./Count 0[gsm@VM-4-3-centos count]$ make clean rm -f Count [gsm@VM-4-3-centos count]$ vim Count.c [gsm@VM-4-3-centos count]$ cat Count.c #include<stdio.h>#include<unistd.h>intmain(){int count =10;while(count >=0){printf("%-2d\r", count);// \r回车,但是没有换行,也就没有刷新fflush(stdout); count--;sleep(1);}printf("\r\n");return0;}[gsm@VM-4-3-centos count]$ make gcc -o Count Count.c [gsm@VM-4-3-centos count]$ ./Count 0[gsm@VM-4-3-centos count]$ make clean rm -f Count [gsm@VM-4-3-centos count]$ ll total 8-rw-rw-r--1 gsm gsm 300 Oct 1222:17 Count.c -rw-rw-r--1 gsm gsm 61 Oct 1221:36 Makefile 
[gsm@VM-4-3-centos lesson7]$ ll total 16-rw-rw-r--1 gsm gsm 223 Oct 1220:15 code.c drwxrwxr-x 2 gsm gsm 4096 Oct 1222:17 count -rw-rw-r--1 gsm gsm 206 Oct 1221:01 Makefile -rw-rw----1 gsm gsm 131 Oct 1221:29 proc.c [gsm@VM-4-3-centos lesson7]$ mkdir processbar [gsm@VM-4-3-centos lesson7]$ ll total 20-rw-rw-r--1 gsm gsm 223 Oct 1220:15 code.c drwxrwxr-x 2 gsm gsm 4096 Oct 1222:17 count -rw-rw-r--1 gsm gsm 206 Oct 1221:01 Makefile -rw-rw----1 gsm gsm 131 Oct 1221:29 proc.c drwxrwxr-x 2 gsm gsm 4096 Oct 1222:21 processbar [gsm@VM-4-3-centos lesson7]$ cd processbar/[gsm@VM-4-3-centos processbar]$ ll total 0[gsm@VM-4-3-centos processbar]$ pwd /home/gsm/112/lesson7/processbar [gsm@VM-4-3-centos processbar]$ touch process.c [gsm@VM-4-3-centos processbar]$ touch process.h [gsm@VM-4-3-centos processbar]$ touch main.c [gsm@VM-4-3-centos processbar]$ ll total 0-rw-rw-r--1 gsm gsm 0 Oct 1222:36 main.c -rw-rw-r--1 gsm gsm 0 Oct 1222:36 process.c -rw-rw-r--1 gsm gsm 0 Oct 1222:36 process.h [gsm@VM-4-3-centos processbar]$ cp ../count/Makefile .[gsm@VM-4-3-centos processbar]$ ll total 4-rw-rw-r--1 gsm gsm 0 Oct 1222:36 main.c -rw-rw-r--1 gsm gsm 61 Oct 1222:37 Makefile -rw-rw-r--1 gsm gsm 0 Oct 1222:36 process.c -rw-rw-r--1 gsm gsm 0 Oct 1222:36 process.h [gsm@VM-4-3-centos processbar]$ vim Makefile [gsm@VM-4-3-centos processbar]$ cat Makefile process:main.c process.c gcc -o $@ $^.PHONY:clean clean: rm -f process [gsm@VM-4-3-centos processbar]$ vim process.h [gsm@VM-4-3-centos processbar]$ vim main.c [gsm@VM-4-3-centos processbar]$ cat process.h #pragmaonce//versionvoidProcess();[gsm@VM-4-3-centos processbar]$ cat process.c #include"process.h"#include<stdio.h>voidProcess(){printf("hello Process\n");}[gsm@VM-4-3-centos processbar]$ cat main.c #include<stdio.h>#include"process.h"intmain(){Process();printf("hello process\n");return0;}[gsm@VM-4-3-centos processbar]$ make gcc -o process main.c process.c [gsm@VM-4-3-centos processbar]$ ll total 28-rw-rw-r--1 gsm gsm 117 Oct 1222:49 main.c -rw-rw-r--1 gsm gsm 74 Oct 1222:39 Makefile -rwxrwxr-x 1 gsm gsm 8424 Oct 1222:52 process -rw-rw-r--1 gsm gsm 91 Oct 1222:47 process.c -rw-rw-r--1 gsm gsm 41 Oct 1222:47 process.h [gsm@VM-4-3-centos processbar]$ ./process hello Process hello process [gsm@VM-4-3-centos processbar]$ make clean rm -f process [gsm@VM-4-3-centos processbar]$ ll total 16-rw-rw-r--1 gsm gsm 117 Oct 1222:49 main.c -rw-rw-r--1 gsm gsm 74 Oct 1222:39 Makefile -rw-rw-r--1 gsm gsm 91 Oct 1222:47 process.c -rw-rw-r--1 gsm gsm 41 Oct 1222:47 process.h [gsm@VM-4-3-centos processbar]$ man 3 usleep [gsm@VM-4-3-centos processbar]$ vim main.c [gsm@VM-4-3-centos processbar]$ vim process.c [gsm@VM-4-3-centos processbar]$ cat process.h #pragmaonce//versionvoidProcess();[gsm@VM-4-3-centos processbar]$ cat process.c #include"process.h"#include<stdio.h>#include<string.h>#include<unistd.h>#defineNUM101#defineSTYLE'#'// version 1voidProcess(){constchar* lable ="|/-\\";int len =strlen(lable);char bar[NUM];memset(bar,'\0',sizeof(bar));int cnt =0;while(cnt <=100){printf("[%-100s][%d%%][%c]\r", bar, cnt, lable[cnt % len]);fflush(stdout); bar[cnt]= STYLE; cnt++;usleep(50000);}printf("\r\n");}[gsm@VM-4-3-centos processbar]$ cat main.c #include<stdio.h>#include"process.h"intmain(){Process();return0;}[gsm@VM-4-3-centos processbar]$ make gcc -o process main.c process.c [gsm@VM-4-3-centos processbar]$ ./process [####################################################################################################][100%][|][gsm@VM-4-3-centos processbar]$ make clean rm -f process [gsm@VM-4-3-centos processbar]$ ll total 16-rw-rw-r--1 gsm gsm 86 Oct 1315:50 main.c -rw-rw-r--1 gsm gsm 74 Oct 1222:39 Makefile -rw-rw-r--1 gsm gsm 496 Oct 1316:41 process.c -rw-rw-r--1 gsm gsm 41 Oct 1222:47 process.h [gsm@VM-4-3-centos processbar]$ vim process.c [gsm@VM-4-3-centos processbar]$ cat process.h #pragmaonce//versionvoidProcess();[gsm@VM-4-3-centos processbar]$ cat process.c #include"process.h"#include<stdio.h>#include<string.h>#include<unistd.h>#defineNUM101#defineSTYLE'='// version 1voidProcess(){constchar* lable ="|/-\\";int len =strlen(lable);char bar[NUM];memset(bar,'\0',sizeof(bar));int cnt =0;while(cnt <=100){printf("[%-100s][%d%%][%c]\r", bar, cnt, lable[cnt % len]);fflush(stdout); bar[cnt]= STYLE; cnt++;if(cnt +1== NUM){printf("[%-100s][%d%%][%c]\r", bar, cnt, lable[cnt % len]);break;} bar[cnt]='>';usleep(50000);}printf("\r\n");}[gsm@VM-4-3-centos processbar]$ cat main.c #include<stdio.h>#include"process.h"intmain(){Process();return0;}[gsm@VM-4-3-centos processbar]$ make gcc -o process main.c process.c [gsm@VM-4-3-centos processbar]$ ./process [====================================================================================================][100%][|][gsm@VM-4-3-centos processbar]$ make clean rm -f process [gsm@VM-4-3-centos processbar]$ ll total 16-rw-rw-r--1 gsm gsm 86 Oct 1315:50 main.c -rw-rw-r--1 gsm gsm 74 Oct 1222:39 Makefile -rw-rw-r--1 gsm gsm 661 Oct 1317:33 process.c -rw-rw-r--1 gsm gsm 41 Oct 1222:47 process.h [gsm@VM-4-3-centos processbar]$ cp process.c process-backup20251013.c [gsm@VM-4-3-centos processbar]$ ll total 20-rw-rw-r--1 gsm gsm 86 Oct 1315:50 main.c -rw-rw-r--1 gsm gsm 74 Oct 1222:39 Makefile -rw-rw-r--1 gsm gsm 661 Oct 1317:34 process-backup20251013.c -rw-rw-r--1 gsm gsm 661 Oct 1317:33 process.c -rw-rw-r--1 gsm gsm 41 Oct 1222:47 process.h [gsm@VM-4-3-centos processbar]$ vim process.c [gsm@VM-4-3-centos processbar]$ cat process.h #pragmaonce//versionvoidProcess();[gsm@VM-4-3-centos processbar]$ cat process.c #include"process.h"#include<stdio.h>#include<string.h>#include<unistd.h>#defineNUM101#defineSTYLE1'>'#defineSTYLE2'='// version 1voidProcess(){constchar* lable ="|/-\\";int len =strlen(lable);char bar[NUM];memset(bar,'\0',sizeof(bar));int cnt =0;while(cnt <100){ bar[cnt]= STYLE1;printf("[%-100s][%d%%][%c]\r", bar, cnt +1, lable[(cnt +1)% len]);fflush(stdout);usleep(100000); bar[cnt]= STYLE2;printf("[%-100s][%d%%][%c]\r", bar, cnt +1, lable[(cnt +1)% len]);fflush(stdout); cnt++;// if (cnt + 1 == NUM)// {// printf("[%-100s][%d%%][%c]\r", bar, cnt, lable[cnt % len]);// break;// }//// bar[cnt] = '>';//usleep(50000);}printf("\r\n");}[gsm@VM-4-3-centos processbar]$ cat main.c #include<stdio.h>#include"process.h"intmain(){Process();return0;}[gsm@VM-4-3-centos processbar]$ make gcc -o process main.c process.c [gsm@VM-4-3-centos processbar]$ ./process [====================================================================================================][100%][|][gsm@VM-4-3-centos processbar]$ make clean rm -f process [gsm@VM-4-3-centos processbar]$ ll total 20-rw-rw-r--1 gsm gsm 86 Oct 1315:50 main.c -rw-rw-r--1 gsm gsm 74 Oct 1222:39 Makefile -rw-rw-r--1 gsm gsm 661 Oct 1317:34 process-backup20251013.c -rw-rw-r--1 gsm gsm 860 Oct 1317:54 process.c -rw-rw-r--1 gsm gsm 41 Oct 1222:47 process.h [gsm@VM-4-3-centos processbar]$ cp process.c process-backup20251013_02.c [gsm@VM-4-3-centos processbar]$ ll total 24-rw-rw-r--1 gsm gsm 86 Oct 1315:50 main.c -rw-rw-r--1 gsm gsm 74 Oct 1222:39 Makefile -rw-rw-r--1 gsm gsm 860 Oct 1317:56 process-backup20251013_02.c -rw-rw-r--1 gsm gsm 661 Oct 1317:34 process-backup20251013.c -rw-rw-r--1 gsm gsm 860 Oct 1317:54 process.c -rw-rw-r--1 gsm gsm 41 Oct 1222:47 process.h 
[gsm@VM-4-3-centos processbar]$ man srand [gsm@VM-4-3-centos processbar]$ man 3 time [gsm@VM-4-3-centos processbar]$ vim main.c [gsm@VM-4-3-centos processbar]$ cat main.c #include<stdio.h>#include<unistd.h>#include<time.h>#include<stdlib.h>#include"process.h"constint base =20;double total =2048.0;// 2048MBdouble once =0.1;voiddownload(){double current =0.0;while(current < total){// 模拟下载行为int r =rand()% base +1;double speed = r * once; current += speed;if(current >= total){ current = total;}usleep(10000);printf("test:%.1lf/%.1lf\r", current, total);fflush(stdout);}printf("\n");}intmain(){srand(time(NULL));download();return0;}[gsm@VM-4-3-centos processbar]$ make gcc -o process main.c process.c [gsm@VM-4-3-centos processbar]$ ./process test:2048.0/2048.0[gsm@VM-4-3-centos processbar]$ make clean rm -f process [gsm@VM-4-3-centos processbar]$ ll total 24-rw-rw-r--1 gsm gsm 657 Oct 1319:24 main.c -rw-rw-r--1 gsm gsm 74 Oct 1222:39 Makefile -rw-rw-r--1 gsm gsm 860 Oct 1317:56 process-backup20251013_02.c -rw-rw-r--1 gsm gsm 661 Oct 1317:34 process-backup20251013.c -rw-rw-r--1 gsm gsm 495 Oct 1319:02 process.c -rw-rw-r--1 gsm gsm 41 Oct 1222:47 process.h [gsm@VM-4-3-centos processbar]$ vim main.c [gsm@VM-4-3-centos processbar]$ vim process.c [gsm@VM-4-3-centos processbar]$ vim process.h [gsm@VM-4-3-centos processbar]$ cat process.h #pragmaonce//version//void Process();//void Process(double total, double current);voidFlushProcess(double total,double current);[gsm@VM-4-3-centos processbar]$ cat process.c #include"process.h"#include<stdio.h>#include<string.h>#include<unistd.h>#defineNUM101#defineSTYLE'='#definePOINT'.'#defineSPACE' 'constint pnum =6;// version 2:真实的进度条,应该根据具体的比如下载的量,来动态刷新进度voidFlushProcess(double total,double current){// 1. 更新当前进度的百分比double rate =(current / total)*100;//printf("test:%.1lf%%\r", rate);//fflush(stdout);// 2. 更新进度条主体char bar[NUM];// 我们认为,1% 更新一个等号memset(bar,'\0',sizeof(bar));for(int i =0; i <(int)rate; i++){ bar[i]= STYLE;}// 3. 更新旋转光标或者是其他风格staticint num =0;char points[pnum +1];memset(points,'\0',sizeof(points));for(int i =0; i < pnum; i++){if(i <= num){ points[i]= POINT;}else{ points[i]= SPACE;}} num++; num %= pnum;// 4. test && printfprintf("[%-100s][%.1lf%%]%s\r", bar, rate, points);fflush(stdout);}// version 1//void Process()//{// const char* lable = "|/-\\";// int len = strlen(lable);// char bar[NUM];// memset(bar, '\0', sizeof(bar));// int cnt = 0;//// while (cnt <= 100)// {// printf("[%-100s][%d%%][%c]\r", bar, cnt, lable[cnt % len]);// fflush(stdout);// bar[cnt] = STYLE;// cnt++;// usleep(50000);// }//// printf("\r\n");//}[gsm@VM-4-3-centos processbar]$ cat main.c #include<stdio.h>#include<unistd.h>#include<time.h>#include<stdlib.h>#include"process.h"typedefvoid(*flush_t)(double total,double current);// 这是一个刷新的函数指针类型constint base =100;double total =2048.0;// 2048MBdouble once =0.1;// 进度条的调用方式voiddownload(flush_t f){double current =0.0;while(current < total){// 模拟下载行为int r =rand()% base +1;double speed = r * once; current += speed;if(current >= total){ current = total;}usleep(10000);// 更新出了本次新的下载量// 根据真实的应用场景,进行动态刷新//Process(total, 1.0);f(total, current);//printf("test:%.1lf/%.1lf\r", current, total);//fflush(stdout);}printf("\n");}intmain(){srand(time(NULL));download(FlushProcess);download(FlushProcess);download(FlushProcess);download(FlushProcess);download(FlushProcess);download(FlushProcess);download(FlushProcess);return0;}[gsm@VM-4-3-centos processbar]$ make gcc -std=gnu99 -o process main.c process.c [gsm@VM-4-3-centos processbar]$ ./process [====================================================================================================][100.0%].....[====================================================================================================][100.0%]......[====================================================================================================][100.0%]....[====================================================================================================][100.0%].....[====================================================================================================][100.0%].[====================================================================================================][100.0%]..[====================================================================================================][100.0%].[gsm@VM-4-3-centos processbar]$ make clean rm -f process [gsm@VM-4-3-centos processbar]$ ll total 24-rw-rw-r--1 gsm gsm 1149 Oct 1412:15 main.c -rw-rw-r--1 gsm gsm 85 Oct 1400:52 Makefile -rw-rw-r--1 gsm gsm 860 Oct 1317:56 process-backup20251013_02.c -rw-rw-r--1 gsm gsm 661 Oct 1317:34 process-backup20251013.c -rw-rw-r--1 gsm gsm 1556 Oct 1412:15 process.c -rw-rw-r--1 gsm gsm 138 Oct 1412:15 process.h 

Read more

假网站排全网第二,真官网翻五页都找不到!NanoClaw创始人破防:SEO之战,我快要输了

假网站排全网第二,真官网翻五页都找不到!NanoClaw创始人破防:SEO之战,我快要输了

整理 | 苏宓 出品 | ZEEKLOG(ID:ZEEKLOGnews) 自从 OpenClaw 爆火之后,各种“Claw”项目接连出现,其中以安全优化版 NanoClaw 最为知名。它的核心代码仅有 4000 行,却获得了 AI 大牛 Andrej Karpathy 的点赞。 可谁也没想到,这款口碑极佳的开源项目,近来竟被一个仿冒网站抢了风头。 投诉无门之下,NanoClaw 创始人 Gavriel Cohen 在 X 社交平台上无奈发文怒斥:谷歌搜索错误地将假网站排在真官网前面,不仅破坏了项目声誉,还埋下了严重的安全隐患,而他费尽心力,却只能哀叹一句——“我正在为自己的开源项目打 SEO 战,但我快要输了。” 那么,NanoClaw 究竟发生了什么?又是怎么走红的?事情还要从 OpenClaw

By Ne0inhk
曝Windows 12将于今年发布?以AI为核心、NPU成「硬件门槛」,网友吐槽:“不想要的全塞进来了”

曝Windows 12将于今年发布?以AI为核心、NPU成「硬件门槛」,网友吐槽:“不想要的全塞进来了”

整理 | 郑丽媛 出品 | ZEEKLOG(ID:ZEEKLOGnews) 当年,微软一句“Windows 10 将是最后一个版本”的表态,让不少用户以为 Windows 进入了“只更新、不换代”的时代。但几年过去,现实却完全不同。 在 Windows 11 发布之后,如今关于 Windows 12 的传闻再次密集出现。从内部代号、代码片段,到硬件厂商的暗示与 OEM 预热标签,种种线索拼在一起,勾勒出一个明显的趋势——这不会只是一次常规升级,而更像是一次围绕 AI 的平台级重构。 更关键的是,这次争议,可能远比当年 TPM 2.0 更大。 精准卡位 Windows 10 退场的时间?

By Ne0inhk
Python热度下滑、AI能取代搜索引擎?TIOBE最新榜单揭晓!

Python热度下滑、AI能取代搜索引擎?TIOBE最新榜单揭晓!

整理 | 屠敏 出品 | ZEEKLOG(ID:ZEEKLOGnews) 日前,TIOBE 发布了最新的 3 月编程语言榜单。整体来看,本月排名变化不算大,但榜单中仍然出现了一些值得关注的小波动。  AI 工具能帮大家秒懂最新编程语言趋势? 由于 2 月天数较少,3 月的榜单整体变化有限。借着这次发布,TIOBE CEO Paul Jansen 也回应了一个最近被频繁讨论的问题:为什么 TIOBE 指数仍然依赖搜索引擎统计结果?在大语言模型流行的今天,直接询问 AI 哪些编程语言最流行,是不是更简单? 对此,Jansen 的回答是否定的。 他解释称,TIOBE 指数本质上统计的是互联网上关于某种编程语言的网页数量。而大语言模型的训练数据同样来自这些网页内容,因此从信息来源来看,两者并没有本质区别。换句话说,LLM 的判断,本质上也是建立在这些网页数据之上的。 Python 活跃度仍在下降

By Ne0inhk
“裸奔龙虾”数量已达27万只,业内人士警告;AI浪潮下,中传“砍掉”翻译等16个专业;薪资谈判破裂,三星电子8.9万人要罢工 | 极客头条

“裸奔龙虾”数量已达27万只,业内人士警告;AI浪潮下,中传“砍掉”翻译等16个专业;薪资谈判破裂,三星电子8.9万人要罢工 | 极客头条

「极客头条」—— 技术人员的新闻圈! ZEEKLOG 的读者朋友们好,「极客头条」来啦,快来看今天都有哪些值得我们技术人关注的重要新闻吧。(投稿或寻求报道:[email protected]) 整理 | 郑丽媛 出品 | ZEEKLOG(ID:ZEEKLOGnews) 一分钟速览新闻点! * “裸奔龙虾”已高达27万只!业内人士警告:一旦黑客入侵,敏感信息一秒搬空 * 阿里云 CTO 周靖人代管千问模型一号位,刘大一恒管理更多团队 * 中国传媒大学砍掉翻译、摄影等 16 个本科专业,直言教育要面向人机分工时代 * 雷军放话:小米将很快推出 L3、L4 的驾驶 * 消息称原理想汽车智驾一号位郎咸朋具身智能赛道创业 * vivo 前产品经理宋紫薇创业,瞄准 AI 时尚Agent,获亿元融资 * MiniMax 发布龙虾新技能,股价暴涨超 23% * 薪资谈判破裂,三星电子

By Ne0inhk