Ubuntu Clean

清理 /boot 目录 查看内核版本 uname -r 列出所有的内核 dpkg --list 'linux-image*' | grep ^ii 卸载没有使用的内核 sudo apt-get remove linux-image-VERSION 清理不再使用的包 sudo apt-get autoremove 更新内核列表 sudo update-grub 清理 /lib/modules 目录 查看已安装的内核版本 apt list --installed linux-image 删除未使用的内核版本对应的目录 sudo rm -rf 5.15.0-70-generic/ 清除未使用的 snap 包 #!/bin/sh LANG=en_US.UTF-8 snap list --all | awk '/disabled/{print $1, $3}' | while read pkg revision; do sudo snap remove "$pkg" --revision="$revision" done

2023-04-21 15:53:23 · 王二

Porto

Porto (Software Architectural Pattern) Welcome to Porto Introduction Getting Started Layers Overview 1) Ship Layer 2) Containers Layer Containers Sections Components 1) Main Components 1.1) Components Interaction Diagram 1.2) Request Life Cycle 1.3) Main Components Definitions & Principles Routes Controllers Requests Actions Tasks Models Views Transformers Exceptions Sub-Actions 2) Optional Components Typical Container Structure Porto Quality Attributes Implementations (Built with Porto) Feedback & Questions Introduction Porto is a modern software architectural pattern, consisting of guidelines, principles and patterns to help developers organize their code in a highly maintainable and reusable way. ...

2023-02-17 13:46:44 · 王二

ApidocJs apigroup Support Chinese

如题 apidoc 的 @apiGroup 值如果是中文的时候没办法进行分组。官方仓库提了好多这样的 issue,貌似韩文也不支持。 有人提了 pr,但是被拒绝了,不知道为什么。 可以临时根据这个 pr 修改文件来支持中文分组,node_modules/apidoc/lib/core/workers/api_group.js 文件中的: group = group.replace(/^[^a-z]+|[^\w:.-]+/gi, ''); 替换为: group = encodeURI(group).replace(/^[^a-z]+|[^\w:.-]+/gi, ''); 这样如果线上部署生成的话就不太方便了,可以在生成文档的脚本文件中添加一行替换的代码,在生成文档前强行替换: sed -i 's/group = group.replace/group = encodeURI\(group\).replace/' node_modules/apidoc/lib/core/workers/api_group.js

2023-02-16 13:39:23 · 王二

int(10)里面的10是什么意思?

crud 惯了,从来没深入研究过这些(一直以为是能存储的字节数)。 查了一下官方文档:Numeric Type Attributes。 MySQL supports an extension for optionally specifying the display width of integer data types in parentheses following the base keyword for the type. For example, INT(4) specifies an INT with a display width of four digits. This optional display width may be used by applications to display integer values having a width less than the width specified for the column by left-padding them with spaces. (That is, this width is present in the metadata returned with result sets. Whether it is used is up to the application.) ...

2022-06-24 12:46:57 · 王二

5-3 会话

会话 会话是一个进程组,或是多个进程组的集合。 一个会话可以至少有一个控制终端(物理终端,伪终端) 一个会话至少有一个前台进程组(前台就是指能输入的 bin/bash ),其它就是后台进程组 一个会话如果连接了一个控制终端,就叫控制进程 因为这个会话首进程 /bin/bash 是连接控制终端(伪终端设置驱动程序+tcp/ip 对端的ssh client) 的,所以创建的子进程,也会继承 bin/bash 的控制终端(0,1,2标准输出,标准输入,标准错误) 在终端的输入会影响前台进程组,ctrl+c (会终止前台进程)。 会话的创建 使用 posix_setsid() / setsid(2)创建。 不能使用组长进程调用 setsid 函数,硬要调用会报错 一般先创建一个子进程,让父进程exit,由子进程调用 setsid 调用 setsid 之后,该进程会变成组长进程,同时也会变成会话首进程 同时该进程没有控制终端(没有终端了,可以认为它没有连接显示器,没有连接键盘) 它没有控制终端了,你在终端里输入任何数据都没有反应的 phpdemo19.php <?php function showPid() { $pid = posix_getpid(); fprintf(STDOUT, "pid=%d,ppid=%d,pgid=%d,sid=%d\n",$pid,posix_getppid(),posix_getpgid($pid),posix_getsid($pid)); } showPid(); $pid = pcntl_fork(); if ($pid > 0) { exit(0); } if (-1 == posix_setsid()) { echo 'error'.PHP_EOL; $erro_no = pcntl_errno(); echo pcntl_strerror($erro_no).PHP_EOL; } else { echo '会话创建成功'.PHP_EOL; } showPid(); while (1) { sleep(2); } 执行结果,注意观察 pgid,sid 变化 ...

2022-06-10 21:37:27 · 王二

5-2 进程组

进程组,就是一个或是多个进程的集合,每一个进程都有个标识「组ID(PGID)」,表示该进程属于哪个进程组。 bash 进程启动之后,它会自己 setsid 把自己设置为会话首进程,也会设置自己为组长进程。 进程:正在执行的程序,这个程序是在 bin/bash 进程里启动的。 进程启动之后(通过 execve 函数启动),它会继承一些属性比如说组ID,会话ID,同时也会继承父进程已经打开的文件描述符(伪终端里的):0/标准输入,1/标准输出,2/标准错误,通过 pts、ptmx 模拟出来的。 demo17.php $pid = posix_getpid(); fprintf(STDOUT, "pid=%d,ppid=%d,pgid=%d,sid=%d\n",$pid,posix_getppid(),posix_getpgid($pid),posix_getsid($pid)); 查看当前 bash 进程 PID $ echo $$ 1031235 另外一个 SSH 连接,追踪上一个 bash 进程 $ strace -f -s 65500 -o demo17.log -p 1031235 在 bash 进程 1031235 中,执行代码 $ php demo17.php pid=1032568,ppid=1031235,pgid=1032568,sid=1031235 demo17.log # bash 进程 clone 一个子进程 1032568 1031235 clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f2c4847ba10) = 1032568 1032568 getpid() = 1032568 ... # 子进程将自己设置为组长进程 1031235 setpgid(1032568, 1032568) = 0 ... # 子进程执行 `demo17.php` 1032568 execve("/usr/bin/php", ["php", "-c", "/www/server/php/80/etc/php-cli.ini", "demo17.php"], 0x5558eda12830 /* 32 vars */) = 0 孤儿进程:指父进程先结束,但是子进程晚结束,这个时候子进程就是孤儿进程,它会被1号进程接管。 ...

2022-05-08 12:31:27 · 王二

5-1 Bash进程与终端

什么是终端 能实现数据输入、输出的统称为终端。 物理终端:传统显示器、键盘,通过 VGA、HDMI、USB 等连接。 软件终端(虚拟终端/伪终端):通过 TCP/IP 协议实现的终端,能模拟出来一个实现「数据输入、输出」的终端,比如:ssh、telnet … 这篇博客介绍的比较详细:「转」彻底理解Linux的各种终端类型以及概念。 伪终端的连接过程 在linux中有物理终端,有虚拟终端(伪终端)。 sshd 服务会打开一个 [dev/ptmx],这个文件是一个伪终端主设备文件。 bin/bash 会打开一个 dev/pts(0,1…), 是一个伪终端从设备文件。 ptmx/ptsx 它们通过伪终端设备驱动程序模拟出输入和输出的功能。 bin/bash 进程就可以实现数据读取和数据写入。 ssh客户端 ——————> 远程服务器的一个进程 ——-> ssh客户端。 输入单元(ssh客户端)——–> /bin/bash进程————–> 输出单元(ssh客户端)。 bin/bash 启动之后,对终端数据的读取和写入就是通过 pts 实现的(能实现标准输入,标准输出)。 dev/pts0 0 1 2 标准输入,标准输出,标准错误。 通过 strace 命令查看sshd服务: strace 前进程关系: ├─sshd,9408 │ └─sshd,2888142 │ └─bash,2888170 │ └─pstree,2889779 -ap strace 中: $strace -f -s 65500 -o sshd.log -p 9408 # strace 查看系统调用,进行一个新的 SSH 连接 strace: Process 9408 attached strace: Process 2888330 attached strace: Process 2888331 attached strace: Process 2888336 attached strace: Process 2888342 attached strace: Process 2888343 attached strace: Process 2888344 attached strace: Process 2888345 attached strace: Process 2888346 attached strace: Process 2888347 attached strace: Process 2888348 attached strace: Process 2888349 attached strace: Process 2888350 attached strace: Process 2888351 attached strace: Process 2888352 attached strace: Process 2888353 attached strace: Process 2888354 attached strace: Process 2888355 attached strace: Process 2888356 attached strace: Process 2888357 attached # 新的SSH连接 strace: Process 2888358 attached strace: Process 2888359 attached strace: Process 2888360 attached strace: Process 2888361 attached strace: Process 2888362 attached strace: Process 2888363 attached strace: Process 2888364 attached strace: Process 2888365 attached strace: Process 2888382 attached ^Cstrace: Process 9408 detached # 终止信号 strace: Process 2888330 detached strace: Process 2888357 detached 新的 SSH 连接以后的进程关系: ...

2022-03-16 15:33:55 · 王二

Laravel 上传 Docx 文件,表单验证不通过

今天客户反映,上传文件报错。 拿到客户的文件 xxxx.docx 自己测试,接口返回 file 必须是一个 jpeg, bmp, png, jpg, doc, docx, xls, xlsx, pdf 类型的文件。,表单验证没通过。 但是项目配置里面已经允许 docx 类型的文件了,为啥会提示文件类型不对。 打印了下文件的 mimeType,结果为 application/vnd.openxmlformats-officedocument.wordprocessingml.document。 了解了下 openxml: Office Open XML(缩写:Open XML、OpenXML或OOXML),为由 Microsoft 开发的一种以 XML 为基础并以ZIP格式压缩的电子文件规范,支持文件、表格、备忘录、幻灯片等文件格式。 ——openxml 既然以 ZIP 格式压缩,那给允许的文件类型里面加上 zip 试试。 试了一下,可以通过验证了。

2022-03-16 12:48:30 · 王二

4-4 发送信号

发送信号的几种形式 kill -s 信号编号|信号名字 进程PID 在程序中使用posix_kill 给一个指定的进程或是进程组发送信号 pcntl_alarm SIGALRM 在终端按下特殊键 ctrl+c、 ctrl+z、ctrl+\ 网络 SIGURG、SIGPIPE、SIGCHLD(当子进程结束的时候) pcntl_signal_dispatch pcntl_signal_dispatch,调用等待信号的处理器。 调用每个等待信号通过 pcntl_signal 安装的处理器。 posix_kill posix_kill,Send a signal to a process. Send the signal to the process with the process identifier process_id. kill, send signal to a process. The kill() system call can be used to send any signal to any process group or process. If pid is positive, then signal sig is sent to the process with the ID specified by pid. ...

2022-03-15 17:42:37 · 王二

4-3 信号集

信号集 信号集是指信号的集合。 主程序可以选择阻塞某些信号,被阻塞的信号集称为阻塞信号集。 当进程阻塞了某个信号(通过 pcntl_sigpromask 来设置信号屏蔽字),如果在运行期间接收到了阻塞的信号时,这个信号的处理程序不会被执行,这个信号会放在被挂起的信号集里(信号未决集)。 sigpending PHP 没有实现这个函数。 examine pending signals. sigpending() returns the set of signals that are pending for delivery to the calling thread (i.e., the signals which have been raised while blocked). The mask of pending signals is returned in set. pcntl_sigpromask pcntl_sigpromask 设置或检索阻塞信号,用来增加,删除或设置阻塞信号,具体行为 依赖于参数how。 pcntl_sigprocmask(int $how, array $set, array &$oldset = ?): bool 参数: how: 设置 pcntl_sigprocmask()函数的行为。 可选值: SIG_BLOCK: 把信号加入到当前阻塞信号中。 SIG_UNBLOCK: 从当前阻塞信号中移出信号。 SIG_SETMASK: 用给定的信号列表替换当前阻塞信号列表。 set: 信号列表。 oldset: 是一个输出参数,用来返回之前的阻塞信号列表数组。 返回值: 成功时返回 true, 或者在失败时返回 false。 ...

2022-03-15 16:54:58 · 王二