proc_lib分析

参考: http://www.cnblogs.com/me-sa/archive/2011/11/22/erlang0017.html

介绍:

在这里插入图片描述
从官方文档介绍可知, proc_lib模块用于启动符合OTP原则的进程, OTP的behavior都是使用proc_lib实现创建新进程,所以说这个模块是OTP的基石.

谈谈proc_lib:spawn与erlang:spawn的区别.

在这里插入图片描述
在这里插入图片描述
从源码可见, proc_lib:spawn最终也是调用erlang:spawn启动进程, 区别是proc_lib:spawn
初始化参数会多出祖先和父进程名字, 并存入进程字典, 最后使用MFA启动进程.

2.进程退出时的不同处理
普通Erlang进程只有退出原因是normal的时候才会被认为是正常退出,使用proc_lib启动的进程退出原因是shutdown或者{shutdown,Term}的时候也被认为是正常退出.因为应用程序(监控树)停止而导致的进程终止,进程退出的原因会标记为shutdown.使用proc_lib创建的进程退出的原因不是normal也不是shutdown的时候,就会创建一个进程崩溃报告,这个会写入默认的SASL的事件handler,错误报告会在只有在启动了SASL的时候才能看到.

  1. proc_lib:start_link.
    在这里插入图片描述
make -C /lib/modules/5.4.0-26-generic/build M=/home/zjc/C/modTest modules make[1]: Entering directory '/usr/src/linux-headers-5.4.0-26-generic' CC [M] /home/zjc/C/modTest/pingStats.o /home/zjc/C/modTest/pingStats.c: In function ‘ping_stat_hook’: /home/zjc/C/modTest/pingStats.c:41:5: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement] 41 | struct ethhdr *eth_header = NULL; | ^~~~~~ /home/zjc/C/modTest/pingStats.c:75:9: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement] 75 | u64 now = get_jiffies_64() * 1000 / HZ; | ^~~ /home/zjc/C/modTest/pingStats.c: In function ‘ping_stat_proc_show’: /home/zjc/C/modTest/pingStats.c:115:5: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode 115 | for (int i = 0; i < ping_data.seq; i++) | ^~~ /home/zjc/C/modTest/pingStats.c:115:5: note: use option ‘-std=c99’, ‘-std=gnu99’, ‘-std=c11’ or ‘-std=gnu11’ to compile your code /home/zjc/C/modTest/pingStats.c:118:29: warning: format ‘%zu’ expects argument of type ‘size_t’, but argument 3 has type ‘int’ [-Wformat=] 118 | seq_printf(m, "%-10zu %-20llu %-16s\n", i + 1, ping_data.stats[i].timestamp, ip_str); | ~~~~~^ ~~~~~ | | | | long unsigned int int | %-10u /home/zjc/C/modTest/pingStats.c: At top level: /home/zjc/C/modTest/pingStats.c:130:21: error: variable ‘ping_stat_proc_ops’ has initializer but incomplete type 130 | static const struct proc_ops ping_stat_proc_ops = { | ^~~~~~~~ /home/zjc/C/modTest/pingStats.c:131:6: error: ‘const struct proc_ops’ has no member named ‘proc_open’ 131 | .proc_open = ping_stat_proc_open, | ^~~~~~~~~ /home/zjc/C/modTest/pingStats.c:131:18: warning: excess elements in struct initializer 131 | .proc_open = ping_stat_proc_open, | ^~~~~~~~~~~~~~~~~~~ /home/zjc/C/modTest/pingStats.c:131:18: note: (near initialization for ‘ping_stat_proc_ops’) /home/zjc/C/modTest/pingStats.c:132:6: error: ‘const struct proc_ops’ has no member named ‘proc_read’ 132 | .proc_read = seq_read, | ^~~~~~~~~ /home/zjc/C/modTest/pingStats.c:132:18: warning: excess elements in struct initializer 132 | .proc_read = seq_read, | ^~~~~~~~ /home/zjc/C/modTest/pingStats.c:132:18: note: (near initialization for ‘ping_stat_proc_ops’) /home/zjc/C/modTest/pingStats.c:133:6: error: ‘const struct proc_ops’ has no member named ‘proc_lseek’ 133 | .proc_lseek = seq_lseek, | ^~~~~~~~~~ /home/zjc/C/modTest/pingStats.c:133:19: warning: excess elements in struct initializer 133 | .proc_lseek = seq_lseek, | ^~~~~~~~~ /home/zjc/C/modTest/pingStats.c:133:19: note: (near initialization for ‘ping_stat_proc_ops’) /home/zjc/C/modTest/pingStats.c:134:6: error: ‘const struct proc_ops’ has no member named ‘proc_release’ 134 | .proc_release = single_release, | ^~~~~~~~~~~~ /home/zjc/C/modTest/pingStats.c:134:21: warning: excess elements in struct initializer 134 | .proc_release = single_release, | ^~~~~~~~~~~~~~ /home/zjc/C/modTest/pingStats.c:134:21: note: (near initialization for ‘ping_stat_proc_ops’) /home/zjc/C/modTest/pingStats.c: In function ‘ping_stat_init’: /home/zjc/C/modTest/pingStats.c:163:43: error: passing argument 4 of ‘proc_create’ from incompatible pointer type [-Werror=incompatible-pointer-types] 163 | proc_create("ping_stat", 0, NULL, &ping_stat_proc_ops); | ^~~~~~~~~~~~~~~~~~~ | | | const struct proc_ops * In file included from /home/zjc/C/modTest/pingStats.c:8: ./include/linux/proc_fs.h:49:24: note: expected ‘const struct file_operations *’ but argument is of type ‘const struct proc_ops *’ 49 | struct proc_dir_entry *proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent, const struct file_operations *proc_fops); | ^~~~~~~~~~~ /home/zjc/C/modTest/pingStats.c: At top level: /home/zjc/C/modTest/pingStats.c:130:30: error: storage size of ‘ping_stat_proc_ops’ isn’t known 130 | static const struct proc_ops ping_stat_proc_ops = { | ^~~~~~~~~~~~~~~~~~ cc1: some warnings being treated as errors make[2]: *** [scripts/Makefile.build:275: /home/zjc/C/modTest/pingStats.o] Error 1 make[1]: *** [Makefile:1719: /home/zjc/C/modTest] Error 2 make[1]: Leaving directory '/usr/src/linux-headers-5.4.0-26-generic' make: *** [Makefile:3: all] Error 2
07-31
huaxi@ubuntu:~/c_projects/kernel_module$ make clean make -C /lib/modules/4.15.0-142-generic/build M=/home/huaxi/c_projects/kernel_module clean make[1]: Entering directory '/usr/src/linux-headers-4.15.0-142-generic' CLEAN /home/huaxi/c_projects/kernel_module/.tmp_versions make[1]: Leaving directory '/usr/src/linux-headers-4.15.0-142-generic' huaxi@ubuntu:~/c_projects/kernel_module$ make make -C /lib/modules/4.15.0-142-generic/build M=/home/huaxi/c_projects/kernel_module modules make[1]: Entering directory '/usr/src/linux-headers-4.15.0-142-generic' CC [M] /home/huaxi/c_projects/kernel_module/ping_stat.o /home/huaxi/c_projects/kernel_module/ping_stat.c:138:21: error: variable ‘ping_fops’ has initializer but incomplete type static const struct proc_ops ping_fops = { ^ /home/huaxi/c_projects/kernel_module/ping_stat.c:139:5: error: unknown field ‘proc_open’ specified in initializer .proc_open = ping_proc_open, ^ /home/huaxi/c_projects/kernel_module/ping_stat.c:139:21: warning: excess elements in struct initializer .proc_open = ping_proc_open, ^ /home/huaxi/c_projects/kernel_module/ping_stat.c:139:21: note: (near initialization for ‘ping_fops’) /home/huaxi/c_projects/kernel_module/ping_stat.c:140:5: error: unknown field ‘proc_read’ specified in initializer .proc_read = seq_read, ^ /home/huaxi/c_projects/kernel_module/ping_stat.c:140:21: warning: excess elements in struct initializer .proc_read = seq_read, ^ /home/huaxi/c_projects/kernel_module/ping_stat.c:140:21: note: (near initialization for ‘ping_fops’) /home/huaxi/c_projects/kernel_module/ping_stat.c:141:5: error: unknown field ‘proc_lseek’ specified in initializer .proc_lseek = seq_lseek, ^ /home/huaxi/c_projects/kernel_module/ping_stat.c:141:21: warning: excess elements in struct initializer .proc_lseek = seq_lseek, ^ /home/huaxi/c_projects/kernel_module/ping_stat.c:141:21: note: (near initialization for ‘ping_fops’) /home/huaxi/c_projects/kernel_module/ping_stat.c:142:5: error: unknown field ‘proc_release’ specified in initializer .proc_release = single_release, ^ /home/huaxi/c_projects/kernel_module/ping_stat.c:142:21: warning: excess elements in struct initializer .proc_release = single_release, ^ /home/huaxi/c_projects/kernel_module/ping_stat.c:142:21: note: (near initialization for ‘ping_fops’) /home/huaxi/c_projects/kernel_module/ping_stat.c: In function ‘ping_stat_init’: /home/huaxi/c_projects/kernel_module/ping_stat.c:152:56: error: passing argument 4 of ‘proc_create’ from incompatible pointer type [-Werror=incompatible-pointer-types] proc_entry = proc_create("ping_stats", 0444, NULL, &ping_fops); ^ In file included from /home/huaxi/c_projects/kernel_module/ping_stat.c:3:0: ./include/linux/proc_fs.h:32:24: note: expected ‘const struct file_operations *’ but argument is of type ‘const struct proc_ops *’ struct proc_dir_entry *proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent, const struct file_operations *proc_fops); ^ cc1: some warnings being treated as errors scripts/Makefile.build:337: recipe for target '/home/huaxi/c_projects/kernel_module/ping_stat.o' failed make[2]: *** [/home/huaxi/c_projects/kernel_module/ping_stat.o] Error 1 Makefile:1584: recipe for target '_module_/home/huaxi/c_projects/kernel_module' failed make[1]: *** [_module_/home/huaxi/c_projects/kernel_module] Error 2 make[1]: Leaving directory '/usr/src/linux-headers-4.15.0-142-generic' Makefile:8: recipe for target 'all' failed make: *** [all] Error
最新发布
08-19
改动后编译继续报错,请解决: felix@W0600144-test2:/mydisk/ping_stat$ make make -C /lib/modules/4.15.0-213-generic/build M=/mydisk/ping_stat EXTRA_CFLAGS="-fno-pic" modules make[1]: Entering directory '/usr/src/linux-headers-4.15.0-213-generic' ./scripts/gcc-goto.sh: line 6: cannot create temp file for here-document: No space left on device CC [M] /mydisk/ping_stat/ping_stat.o /mydisk/ping_stat/ping_stat.c: In function ‘ping_stat_show’: /mydisk/ping_stat/ping_stat.c:118:50: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘long int’ [-Wformat=] snprintf(time_buf, sizeof(time_buf), "%04d-%02d-%02d %02d:%02d:%02d", ~~~^ %04ld tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, ~~~~~~~~~~~~~~~~~ /mydisk/ping_stat/ping_stat.c: At top level: /mydisk/ping_stat/ping_stat.c:138:21: error: variable ‘ping_stat_fops’ has initializer but incomplete type static const struct proc_ops ping_stat_fops = { ^~~~~~~~ /mydisk/ping_stat/ping_stat.c:139:6: error: ‘const struct proc_ops’ has no member named ‘proc_open’ .proc_open = ping_stat_open, // 打开时调用 ^~~~~~~~~ /mydisk/ping_stat/ping_stat.c:139:18: warning: excess elements in struct initializer .proc_open = ping_stat_open, // 打开时调用 ^~~~~~~~~~~~~~ /mydisk/ping_stat/ping_stat.c:139:18: note: (near initialization for ‘ping_stat_fops’) /mydisk/ping_stat/ping_stat.c:140:6: error: ‘const struct proc_ops’ has no member named ‘proc_read’ .proc_read = seq_read, // 读操作 ^~~~~~~~~ /mydisk/ping_stat/ping_stat.c:140:18: warning: excess elements in struct initializer .proc_read = seq_read, // 读操作 ^~~~~~~~ /mydisk/ping_stat/ping_stat.c:140:18: note: (near initialization for ‘ping_stat_fops’) /mydisk/ping_stat/ping_stat.c:141:6: error: ‘const struct proc_ops’ has no member named ‘proc_lseek’ .proc_lseek = seq_lseek, ^~~~~~~~~~ /mydisk/ping_stat/ping_stat.c:141:19: warning: excess elements in struct initializer .proc_lseek = seq_lseek, ^~~~~~~~~ /mydisk/ping_stat/ping_stat.c:141:19: note: (near initialization for ‘ping_stat_fops’) /mydisk/ping_stat/ping_stat.c:142:6: error: ‘const struct proc_ops’ has no member named ‘proc_release’ .proc_release = single_release, ^~~~~~~~~~~~ /mydisk/ping_stat/ping_stat.c:142:21: warning: excess elements in struct initializer .proc_release = single_release, ^~~~~~~~~~~~~~ /mydisk/ping_stat/ping_stat.c:142:21: note: (near initialization for ‘ping_stat_fops’) /mydisk/ping_stat/ping_stat.c: In function ‘ping_stat_init’: /mydisk/ping_stat/ping_stat.c:162:44: warning: passing argument 4 of ‘proc_create’ from incompatible pointer type [-Wincompatible-pointer-types] if (!proc_create("ping_stat", 0, NULL, &ping_stat_fops)) { ^ In file included from /mydisk/ping_stat/ping_stat.c:8:0: ./include/linux/proc_fs.h:32:24: note: expected ‘const struct file_operations *’ but argument is of type ‘const struct proc_ops *’ struct proc_dir_entry *proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent, const struct file_operations *proc_fops); ^~~~~~~~~~~ /mydisk/ping_stat/ping_stat.c: At top level: /mydisk/ping_stat/ping_stat.c:138:30: error: storage size of ‘ping_stat_fops’ isn’t known static const struct proc_ops ping_stat_fops = { ^~~~~~~~~~~~~~ scripts/Makefile.build:340: recipe for target '/mydisk/ping_stat/ping_stat.o' failed make[2]: *** [/mydisk/ping_stat/ping_stat.o] Error 1 Makefile:1596: recipe for target '_module_/mydisk/ping_stat' failed make[1]: *** [_module_/mydisk/ping_stat] Error 2 make[1]: Leaving directory '/usr/src/linux-headers-4.15.0-213-generic' Makefile:12: recipe for target 'all' failed make: *** [all] Error 2
08-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值