times
- bash built-in
1 | times |
- function
1 |
|
1 | times |
1 | #include <sys/times.h> |
See this example
1 | char ** backtrace_symbols (void *const *buffer, int size) |
The return value of backtrace_symbols is a pointer obtained via the malloc function, and it is the responsibility of the caller to free that pointer. Note that only the return value need be freed, not the individual strings.
Question: Why does it say “only the return value need be freed, not the individual strings”?
Let us observe the defintion of the malloc/free functions first:
1 | void *malloc( size_t size ); |
free takes a void* pointer to deallocate the memory, it doesn’t care what type it is, even if it is a multi-level pointer. It means that malloc has stored the memory size in some place and free will find it beforing deallocate the memory.
Let us return the question. The memory pointer returned by backtrace_symbols is the char** type, it must be a whole block contigunous memory using malloc and might be enforced to be transformed as char** pointer when returing. So when we free the memory block, the Linux kernel find its actual memory size and deallocate it.
Example:
1 | #include <string.h> |
More elegant but less economical code:
1 | #include <string.h> |
Options:
-t, --field-separator=SEP
use SEP instead of non-blank to blank transition
-k, --key=POS1[,POS2]
start a key at POS1 (origin 1), end it at POS2 (default end of line)
-h, --human-numeric-sort
compare human readable numbers (e.g., 2K 1G)
-n, --numeric-sort
compare according to string numerical value
print the number of processing units avaiable.
read the binary file.
Notes: byte order
1 | $ echo -n "ABCD" | xxd |
Can be used to compare binary or non-binary files.
compare two sorted files line by line.
1 | $ cat file1.txt |
The file must be sorted before using the comm command. Otherwise it will complain that:
comm: file 1 is not in sorted order
and cannot work correctly. For example,
1 | $ cat file1.txt |
Syntax:
diff -u file1 file2
Options:
-e, --ed
output an ed script
-u, -U NUM, --unified[=NUM]
output NUM (default 3) lines of unified context
(that is, print NUM lines before and after the difference line)
Use a GUI to display the differences.
Prints less information comparing to diff.
Syntax:
cmp file1 file2
struct/union/array默认支持列表初始化。
Struct and union initialization
Array initialization
1 | #include <bits/stdc++.h> |
1 | #include <bits/stdc++.h> |
[ ]和test是bash的内部命令,[[ ]]是shell的条件判断关键字。
1 | $ type [ |
[ ]和test是等价的,用于评估条件表达式。可以使用man [或help [查阅帮助文档。
1 | $ help [ |
[[ ]]关键字可以屏蔽shell特殊符号,比如&&、||、>和<可以被认为是条件判断符而不是重定向符。
[ ]中使用-a和-o表示逻辑与和逻辑或,[[ ]]中则使用&&和||。
$()用于命令替换。(( )):在比较过程中使用高级数学表达式。请阅读:All about {Curly Braces} in Bash
${}用于引用变量。
与$var相比,${var}是一种消除歧义的措施,比如:
1 | $ var=abc |
{}表示分组。
man 7 glob
glob - globbing pathnames. glob is a shell built-in.
主要用于匹配带有通配符的文件路径。其匹配字符串的能力比正则表达式弱。
它最初是贝尔实验室 Unix 系统上的一个名叫 glob 的命令(glob 是 global 的缩写),用于展开命令行中的通配符。后来系统提供了该功能的 C 语言库函数glob(),知名的 shell 解释器就使用了该接口,shell 脚本和命令行中使用的 glob 模式匹配功能便源自于此。——见博客。
{}严格来讲不属于glob的范畴,其在shell表示一个分组,见:All about {Curly Braces} in Bash。
1 | awk -F' *|:' '/LISTEN/{print $2}' |
其中,-F表示分隔符;
*|:是一个正则表达式,表示以"一个或多个空格"或":"作为分隔符;
再其后的//中是另一个正则表达式,用于匹配文本;
{}中是action。
if-else in awk
use AND and OR in an awk program
1 | awk '{if ($1 > 49151 && $1 < 65536) {print $1} }' |
等价于
1 | awk '$1 > 49151 && $1 < 65536' |
In AWK, BEGIN and END are special patterns that allow you to execute code before processing the input (BEGIN) or after processing all the input (END).
BEGIN block is executed once at the beginning of the AWK program and it is typically used for initializing variables or performing setup tasks.END block is executed once after processing all input, and it is commonly used for final caclucations, summaries, or printing results.$ 用于引用field,例如$1代表第一个field(典型来说是第一列)。NF 表示number of filed,假设一共有7列,那么$NF与$7等价。1 | # "$$"是为了转义"$" |
1 | # 从1025开始找出已经存在的端口,如果相邻端口的gap大于1,则返回“当前端口号+1” |
1 | #这不是正则表达式 |
以下文件可以删除:
.vscode-server/data/User/workspaceStorage/*:几十 GB.
.vscode-server:参考
.config: 可以针对每个目录找到相应的程序,比如 Chrome,然后有针对性地删除一些文件。参考
这里。
.cache: 和 .config 类似处理,参考
这里。
.cache/vscode-cpptools: This cache folder stores cached precompiled headers or “ipch” files that
the IntelliSense engine uses to improve performance. You can limit the size of the cache by
changing the setting value of C_Cpp.intelliSenseCacheSize. 参考
这里:

Ctrl Shift \Remote - SSH: Windows 连接 Linux。前置条件:Windows 本身需要安装 ssh 命令行工具。Perforce for VS Code: perforce 工具。intent-rainbow: 用彩色显示缩进。C/C++Makefile ToolsVerilog FormatAll in onec/c++ definition generatorKoroFileHeader: 参考 这里。BigView
Text Editor 一样,在右下角设置高亮语法Maximus
Open Log Viewer
Command Palette 手动打开配置文件:
在 ~.cshrc 脚本中添加:
1 | ## Use VSCode to diff/merge the Perforce code |
🚀 解决方案一:切换 IntelliSense 引擎 VSCode 默认使用的是 “Default” 引擎,它功能强但对大型项目解析慢
。你可以改成更轻量的 Tag Parser:
操作步骤:打开 VSCode 设置(Ctrl + ,)
搜索 C_Cpp.intelliSenseEngine
将值从 “Default” 改为 “Tag Parser”
这样跳转速度会明显提升,尤其在大型项目中。
⚙️ 解决方案二:优化智能提示延迟在设置中调整提示延迟也能改善体验:
搜索 Editor: Quick Suggestions Delay,设为 10ms 以下
搜索 Snippets Prevent Quick Suggestions,设为 false
这些设置可以让提示和跳转更流畅。
🧠 额外建议关闭未使用的扩展:某些扩展会拖慢性能
使用 compile_commands.json:如果你用 CMake,可以生成这个文件,让 VSCode 更准确地解析项目结构
避免打开整个大型项目目录:只打开你正在编辑的子目录,有助于减少分析负担
🔧 Clang 生态工具(最主要用户)
这些工具依赖 compile_commands.json 来正确解析代码:
.clangd 文件;~/.config/clangd/config.yaml 。🖥️ 智能 IDE 和编辑器 VSCode:
通过 C/C++ 插件读取 compile_commands.json 来加速跳转和补全
🛠️ 构建工具和生成方式 CMake:
最常见的生成方式,只需添加参数:
1 | cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. |
就会在构建目录中生成该文件
Bear 工具:适用于非 CMake 项目(如 Makefile),通过拦截编译命令生成该文件
Setting -> 搜索 “workbench.colorCustomizations” --> “Edit in setting.json”
写入以下内容:
1 | "workbench.colorCustomizations": { |
backtrace
backtrace_symbols
backtrace_symbols_fd
1 | #include <execinfo.h> |
breakpad: https://blog.csdn.net/weixin_45609638/article/details/125090204
obj-m: 链接
make modules: 链接
Makefile:
obj-m += hello-1.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
make -C changes to a new directory where the new makefiles will be run.
M=$(PWD) defines a variable M which the child makefiles can use.
insmod: 插入一个模块(.ko)到kernel中。rmmod: 从内核中删除一个模块。modprobe: 从内核中增删模块。modprobe从/lib/modules/`uname -r`中搜索所有的模块和其他文件,除了/etc/modprobe.d目录中的可选配置文件(参见modprobe.d(5))。lsmod: 显示当前加载的内核模块的状态(即对/proc/modules内容的格式化)。modinfo: 从命令行指定的内核模块中提取信息,如果没有给出模块名称,那么会搜索/lib/modules/version目录,就像modprobe加载模块时一样。depmod: 生成modules.dep和映射文件。dmesg: 打印或控制内核ring buffer(存储kernel message)。