Programming abstractions in C阅读笔记:p184-p195

《Programming Abstractions In C》学习第62天,p184-p195总结。

一、技术总结

1.mutual recursion

2.natural number

(1)定义

p184, If you limit the domain of possible values to the set of natural numbers,which are defined simply as the set of nonnegative integers.

3.最大公约数

/*
 * p191. 3. The greatest common divisor(g.c.d) of two nonnegative integers is the
 * largest integer that divides evenly into both. In the third century B.C., the
 * Greek mathematician Euclid discovered that the greatest common divisor of x
 * and y can always be computed as follows:
 *
 * If x is evenly divisible by y, then y is the greatest common divisor.
 * Otherwise, the greatest common divisor of x and y is always equal to the
 * greatest common divisor of y and the remainder of x divided by y.
 *
 * Use Euclid insight to write a recursive function GCD(X, Y) that computes the
 * greatest common divisor x and y.
 */
#include <stdio.h>

int gcd(int x, int y);

/*
 * function: gcd
 * Usage: int(x, y)
 * ------------
 */
int gcd(int x, int y) {
    if (x % y == 0) {
        return y;
    }
    return gcd(y, x % y);
}


int main() {
    int result;
    result = gcd(16, 28);
    printf("GCD=%d\n", result);  // GCD=4
    return 0;
}

二、英语总结

1.holistic是什么意思?

答:

(1)holistic: holism + -istic。adj. treat the whole of sth and not just a part(整体的)。

(2)holism: holos(“whole”,来自于“*sole”,完整的) + -ism(word-forming element making nouns implying a practice, system, doctrine, etc. 构成词的元素,暗示实践、制度、学说等)。u. the belief that each thing is a whole that is more important the parts that make it up,整体论。

(3)-istic: adjectival word-forming element(构成形容词的元素)。

(4)示例:p185, Maintain a holistic perspective(保持整体的观点)。

2.philosophical是什么意思?

(1)philosophical: philosophy + -ical。adj. relating to the study of philosophy(哲学的)。

(2)philosophy: philo-(“loving”) + sophia(“knowledge, wisdom”),哲学。

3.devote是什么意思?

答:de-(down from,away from, 离开) + vow(to vow“make a promise to do sth, 发誓”),即as if by vow。

(1) vt. to use sth for a particular purpose(使用)。p185,In Chapter 2 of The Art and Science of C, I devote one section to the philosophical concepts of holism and reductionnism(在《在C语言的科学与艺术》第二章,我专门用一节来介绍整体论与还原论这两个哲学概念。)

4.odds are good是什么意思?

答:

(1)odds: n. the probalility that a particular thing will or will not happend(可能性)。

(2)odds are good: There is a high probability that it will happen(可能性很大)。

(3)示例:p185,After all, when you write a program, the odds are good–even if you are an experienced programmer–that your program won’t work the first time。

三、参考资料

1. 编程

(1)Eric S.Roberts,《Programming Abstractions in C》:https://book.douban.com/subject/2003414

2. 英语

(1)Etymology Dictionary:https://www.etymonline.com

(2) Cambridage Dictionary:https://dictionary.cambridge.org

欢迎搜索及关注:编程人(a_codists)

具有多种最大功率点跟踪(MPPT)方法的光伏发电系统(P&O-增量法-人工神经网络-模糊逻辑控制-粒子群优化)之使用粒子群算法的最大功率点追踪(MPPT)(Simulink仿真实现)内容概要:本文介绍了一个涵盖多个科研领域的综合性MATLAB仿真资源集合,重点聚焦于光伏发电系统中基于粒子群优化(PSO)算法的最大功率点追踪(MPPT)技术的Simulink仿真实现。文档还列举了多种MPPT方法(如P&O、增量电导法、神经网络、模糊逻辑控制等),并展示了该团队在电力系统、智能优化算法、机器学习、路径规划、无人机控制、信号处理等多个方向的技术服务能力与代码实现案例。整体内容以科研仿真为核心,提供大量可复现的Matlab/Simulink模型和优化算法应用实例。; 适合人群:具备一定电力电子、自动控制或新能源背景,熟悉MATLAB/Simulink环境,从事科研或工程仿真的研究生、科研人员及技术人员。; 使用场景及目标:①学习并实现光伏系统中基于粒子群算法的MPPT控制策略;②掌握多种智能优化算法在电力系统与自动化领域的建模与仿真方法;③获取可用于论文复现、项目开发和技术攻关的高质量仿真资源。; 阅读建议:建议结合提供的网盘资料,按照研究方向选取对应模块进行实践,重点关注Simulink模型结构与算法代码逻辑的结合,注重从原理到仿真实现的全过程理解,提升科研建模能力。
root@ecm-e00f:/# systemctl status apparmor × apparmor.service - Load AppArmor profiles Loaded: loaded (/lib/systemd/system/apparmor.service; disabled; preset: enabled) Active: failed (Result: exit-code) since Wed 2025-06-25 17:05:34 CST; 45s ago Docs: man:apparmor(7) https://gitlab.com/apparmor/apparmor/wikis/home/ Process: 338199 ExecStart=/lib/apparmor/apparmor.systemd reload (code=exited, status=1/FAILURE) Main PID: 338199 (code=exited, status=1/FAILURE) CPU: 39ms Jun 25 17:05:34 ecm-e00f apparmor.systemd[338206]: AppArmor parser error for /etc/apparmor.d in profile /etc/ap> Jun 25 17:05:34 ecm-e00f apparmor.systemd[338208]: AppArmor parser error for /etc/apparmor.d in profile /etc/ap> Jun 25 17:05:34 ecm-e00f apparmor.systemd[338228]: AppArmor parser error for /etc/apparmor.d/lsb_release in pro> Jun 25 17:05:34 ecm-e00f apparmor.systemd[338232]: AppArmor parser error for /etc/apparmor.d/nvidia_modprobe in> Jun 25 17:05:34 ecm-e00f apparmor.systemd[338236]: AppArmor parser error for /etc/apparmor.d/sbin.dhclient in p> Jun 25 17:05:34 ecm-e00f apparmor.systemd[338242]: AppArmor parser error for /etc/apparmor.d/usr.bin.man in pro> Jun 25 17:05:34 ecm-e00f apparmor.systemd[338199]: Error: At least one profile failed to load Jun 25 17:05:34 ecm-e00f systemd[1]: apparmor.service: Main process exited, code=exited, status=1/FAILURE Jun 25 17:05:34 ecm-e00f systemd[1]: apparmor.service: Failed with result 'exit-code'. Jun 25 17:05:34 ecm-e00f systemd[1]: Failed to start apparmor.service - Load AppArmor profiles.
06-26
<think>我们正在处理AppArmor加载配置文件失败的问题,错误信息提示解析错误(parsererrors)。根据引用[1],我们可以检查AppArmor的状态和已加载的配置文件。引用[2][3]提到了与Python模块相关的错误,但我们的问题更可能是配置文件语法错误。引用[4]提到了pyflakes,这是一个Python代码检查工具,但可能与配置文件语法检查无关。引用[5]是关于硬件操作的,不相关。解决步骤:1.**检查AppArmor状态**:使用`sudoaa-status`查看当前状态,但问题可能出现在启动时加载配置文件失败。2.**检查日志**:使用`journalctl-uapparmor-xe`查看详细错误日志,定位具体是哪个配置文件出错。3.**测试所有配置文件语法**:使用`apparmor_parser`工具检查配置文件的语法:```bashsudoapparmor_parser-QT/etc/apparmor.d/*```这将测试所有配置文件的语法,并报告错误位置。4.**修复或禁用错误配置文件**:-如果发现具体哪个文件出错,可以尝试修复该文件(根据错误信息调整语法)。-如果暂时无法修复,可以移动该文件到备份目录(如`/etc/apparmor.d/disable/`),然后重新加载AppArmor:```bashsudomv/etc/apparmor.d/problem_profile/etc/apparmor.d/disable/sudosystemctlrestartapparmor```5.**重新加载配置文件**:修复后,重新加载配置文件:```bashsudosystemctlreloadapparmor```6.**验证**:再次检查状态和日志:```bashsudoaa-statussystemctlstatusapparmor```**注意**:如果多个文件出错,可能需要逐个修复。常见错误包括语法错误(如缺少括号、错误的规则格式)或包含不存在的文件。如果问题涉及Python模块(如引用[2][3]中的错误),可能是`aa-genprof`等工具的问题,但这不影响AppArmor服务本身。但若配置文件是由这些工具生成且包含错误,则仍需修复配置文件。**引用标识**:在回答中引用相关段落时,在末尾添加引用标识,例如:AppArmor配置文件存储在`/etc/apparmor.d/`目录下[^1]。生成相关问题:1.如何调试AppArmor配置文件语法错误?2.AppArmor服务启动失败的其他常见原因有哪些?3.如何临时禁用AppArmor配置文件?根据以上思路,编写回答。</think>### 解决 AppArmor 配置文件加载失败问题(Parser Errors) 当 AppArmor 服务因配置文件解析错误而启动失败时,根本原因是配置文件存在语法或结构问题。以下是系统化的解决步骤: #### 步骤 1:定位错误配置文件 ```bash sudo journalctl -u apparmor -xe --since "1 hour ago" | grep "AppArmor parser error" ``` 检查输出中明确指出的错误文件和行号,例如: ``` Profile /etc/apparmor.d/usr.sbin.mysqld failed to load: Syntax error at line 15 ``` #### 步骤 2:批量检查配置文件语法 ```bash # 测试所有配置文件的语法(-Q=安静模式,-T=显示错误) sudo apparmor_parser -QT /etc/apparmor.d/* ``` 输出示例: ``` Error: Could not open 'abstractions/missing_file' (No such file or directory) in profile /etc/apparmor.d/nginx Syntax error at line 22 in /etc/apparmor.d/custom_profile ``` #### 步骤 3:修复常见错误类型 | 错误类型 | 修复方法 | 示例 | |---------|----------|------| | **包含文件缺失** | 创建缺失文件或注释包含行 | `sudo touch /etc/apparmor.d/abstractions/missing_file` | | **语法错误** | 按规范修正规则 | 错误:`/data/** rw,` → 修正:`/data/** rw,` | | **规则冲突** | 删除重复规则 | 删除重复的 `capability net_bind_service` | | **路径错误** | 验证路径是否存在 | `/var/run/nonexist.sock` → 改为实际路径 | #### 步骤 4:临时禁用问题配置(紧急恢复) ```bash # 移动错误配置文件到隔离目录 sudo mkdir -p /etc/apparmor.d/disable/ sudo mv /etc/apparmor.d/faulty_profile /etc/apparmor.d/disable/ # 重新加载服务 sudo systemctl restart apparmor ``` #### 步骤 5:深度修复配置文件 1. **使用调试模式**: ```bash sudo apparmor_parser -d -T /etc/apparmor.d/problem_profile ``` 2. **检查依赖抽象层**: ```bash grep 'include' /etc/apparmor.d/problem_profile | while read line; do echo "Checking: ${line#include <}"; ls "/etc/apparmor.d/${line#include <}" done ``` 3. **重建配置文件**(参考引用[2]): ```bash sudo aa-genprof /path/to/application # 需要安装apparmor-utils ``` #### 步骤 6:验证修复结果 ```bash # 检查服务状态 sudo systemctl status apparmor # 确认配置文件加载 sudo aa-status | grep "profiles are loaded" ``` 成功输出应显示: ``` 15 profiles are loaded. ``` > **重要提示**:操作前备份配置: > ```bash > sudo cp -a /etc/apparmor.d{,.bak_$(date +%F)} > ``` ### 常见错误原因 1. **手动编辑错误**:直接修改配置文件导致语法错误 2. **抽象层缺失**:`#include <abstractions/...>` 指向不存在的文件[^1] 3. **工具链问题**:`aa-genprof` 因 Python 模块缺失生成错误配置(引用[2][3]) 4. **版本不兼容**:旧版配置文件在新版 AppArmor 中失效
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值