2021年7月8日
printf 变 puts /* main.c */ #include <stdio.h> int main(int argc, char *argv[]) { printf("hello world!\n"); return 0; } $ gcc main.c -nostdlib /usr/bin/ld: 警告: 无法找到项目符号 _start; 缺省为 0000000000001030 /usr/bin/ld: /tmp/cc0k0Sjn.o: in function `main': main.c:(.text+0x1b): undefined reference to `puts' collect2: error: ld returned 1 exit status -nostdlib 选项是让 gcc 不链接标准库。……
阅读全文
2021年7月4日
内联函数 在 C 语言中,我们可以指定编译器将一个函数代码直接复制到调用其代码的地方执行。这种函数调用方式和默认压栈调用方式不同,我们称这种函数为……
阅读全文
2021年6月24日
误解 如果,你问一个程序员,touch 命令是干什么的? 我相信 10 个里面有 8 个会回答:创建一个空文件。 然而,事实真的如此吗? 本意 man touch Linux man 手册里面介……
阅读全文
2021年6月18日
ifconfig ra0 up 这句命令调用的是 pNetDevOps->ndo_open,也就是 main_virtual_if_open /* * ======================================================================== * Routine Description: * Open raxx interface. * ======================================================================== */ int main_virtual_if_open(struct net_device *net_dev) { if (VIRTUAL_IF_INIT(pAd, net_dev) != 0) return -1; if (VIRTUAL_IF_UP(pAd, net_dev) != 0) //……
阅读全文
2021年6月6日
有些命令不支持输入流 前面我们讲过,有些命令是不支持输入流的,只支持命令行参数,如最常用的 ls。我们通常这样使用 $ ls /var/ backups cache crash lib local lock log mail metrics opt run snap……
阅读全文
2021年6月6日
先上代码 shell.c #include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <errno.h>#include <sys/types.h>#include <sys/wait.h> #define MAXLINE 4096 /* max line length */ int main(int argc, char *argv[]) { char buf[MAXLINE]; pid_t pid; int status; printf("%% "); /* print prompt (printf requires %% to print %) */ while (fgets(buf, MAXLINE, stdin) != NULL) { if (buf[strlen(buf) - 1] == '\n') buf[strlen(buf) - 1] = '\0'; /* replace newline with NULL */ if……
阅读全文
2021年6月5日
哪些命令支持输入流 cat, more, less, head, tail, cut, sort, wc, sed … 哪些命令不支持输入流 ls, pwd, cd … 什么是输入流 输入流就是标准输入,在 C 程序里习惯记为 STDIN_FILENO……
阅读全文
2021年5月29日
05/29 Kevin Kelly 给年轻人的99条建议 10/28 libc、glibc和glib的关系 Linux常用系统调用列表 Linux系统调用列表 ## linux 内核源码下载镜像站 strong_alias && weak_alias……
阅读全文
2021年5月25日
less is more less 程序是早期 Unix 程序 more 的改进版。……
阅读全文