[置顶] PID算法C源代码

WEB2.0 jackxiang 2010-6-16 10:31
除开strace外还有一款性能分析工具:
sudo yum install perf
perf record -F max -a -g -- screen -ls

perf record -F max -a -g -- screen -ls
info: Using a maximum frequency rate of 11,000 Hz
There is a screen on:
        16882.abc       (Detached)
1 Socket in /var/run/screen/S-root.

[ perf record: Woken up 14 times to write data ]
[ perf record: Captured and wrote 4.143 MB perf.data (34888 samples) ]
可在不同设备上读取的perf.data 文件. 您可以使用 perf 工具将性能数据记录到 perf.data 文件中,以便在不同的设备上分析。


echo Soft: $(ulimit -Sn)
echo Hard: $(ulimit -Hn)
Soft: 1024000
Hard: 1024000

立即生效的解决办法(重启配置失效):
ulimit -Sn 10000
ulimit -Hn 50000

重启后永久生效实操:
要在 CentOS 7 上永久设置 `ulimit`,您需要修改 `/etc/security/limits.conf` 文件。这个文件允许您设置系统级别的资源限制。您可以按照以下步骤进行修改:

1. 打开终端并以 root 用户身份登录。
2. 使用文本编辑器(如 `vi` 或 `nano`)打开 `/etc/security/limits.conf` 文件:

```bash
sudo vi /etc/security/limits.conf
```

3. 在文件末尾添加以下行:

```
*       soft    nofile  10000
*       hard    nofile  50000
```

这里,`soft` 代表软限制,`hard` 代表硬限制。软限制是系统允许的最大值,超过此限制时会发出警告。硬限制是系统允许的绝对最大值,超过此限制时会导致操作失败。通常情况下,软限制和硬限制是相同的。

4. 保存并关闭文件。在 vi 中,您可以按 `Esc` 键输入 `:wq` 然后按 `Enter` 保存并退出。

5. 重新启动系统或重新登录以使更改生效。

现在 `ulimit` 的设置应该在系统重新启动后生效,并且将永久保持。

fix: Normalize RLIMIT_NOFILE (LimitNOFILE) to sensible defaults:
https://github.com/moby/moby/pull/45534

gnu screen run extremely slow when using 'root' user in container since docker 23.0.1 #45380:
https://github.com/moby/moby/issues/45380


=============================================================

火焰图
on-cpu火焰图可以用于分析cpu是被哪些线程、哪些函数占用的,可以方便的找到热点代码便于后续分析优化。下面我们介绍下火焰图的生成和使用方法。

使用方法
准备FlameGraph工具。
git clone https://github.com/brendangregg/FlameGraph.git
用perf record采集CPU信息。
perf record -e cpu-clock -g  ./perf_test
Ctrl+c结束执行后,在当前目录下会生成采样数据perf.data。

用perf script工具对perf.data进行解析。
perf script -i perf.data &> perf.unfold
将perf.unfold中的符号进行折叠。
./stackcollapse-perf.pl perf.unfold &> perf.folded
最后生成svg图。
./flamegraph.pl perf.folded > perf.svg
perf.svg 用浏览器就可以打开

来自:https://github.com/moby/moby/pull/45534
对于:[实践OK]串口学习之上位机查询模式,下位机arduino采用中断方式读取上位机的指令并crc验证其准确性后读取Tsic506的温度值,再通过CRC校验后经串口发送到上位机。https://jackxiang.com/post/12322/ 这部分串口问题的读取采用select模型的细节分析。

优秀,但最终有一个点仍然想向您探讨一下,上面您给修复后的代码片段中这一外逻辑:
            } else if (num_bytes == 0) {
                // 串口关闭或无数据可读
                perror("Serial port closed or no data available");
                exit(EXIT_FAILURE);
            } else {
                // 读取出错
                perror("Error reading from serial port");
                exit(EXIT_FAILURE);
            }

上面代码子片段中,} else if (num_bytes == 0) {,是在select模型中通知有数据可以读到,我理解至少有一个byte及以上不会是0个byte,它什么样的情况下会出现:num_bytes == 0,再就是这种情况是串口硬件问题还是软件问题,是否可以了也给它一个修复 的机会呢?和select 模型一样:
               if (consecutive_failures >= 5) {
                // 连续失败超过5次,发送错误信息到服务器
                send_error_to_server();
                // 退出程序
                exit(EXIT_FAILURE);
            }  
            continue;

还是必须直接exit(EXIT_FAILURE);更为妥当呢?

二是:
            } else {
                // 读取出错
                perror("Error reading from serial port");
                exit(EXIT_FAILURE);
            }

这部分如果串口读取出错,是否有什么标志位呢,直接放在else中就读取出错,是否有些武断了些,我想要是更谨慎编码,也请给出对应的最后else分支的读取出错的标志判断代码,让这部分代码更加健壮:            } else {
                // 读取出错
                perror("Error reading from serial port");
                exit(EXIT_FAILURE);
            }

,我的两点要求问完了,您可以按条回复解答的同时,给出最终解决后并后的代码,十分感谢 。


回答:
关于您的第一个问题,`num_bytes == 0` 的情况通常表示从串口读取到的字节数为 0,即读取操作没有返回任何数据。这可能是因为串口关闭或者是没有数据可读。如果您认为这种情况是由于串口硬件问题而不是程序逻辑问题导致的,那么直接退出程序可能是更为合适的选择。因此,直接使用 `exit(EXIT_FAILURE)` 可能更为妥当。

对于第二个问题,如果串口读取出错,通常会返回 -1,并将 `errno` 设置为适当的错误代码。您可以根据 `errno` 的值来进一步判断错误的类型。因此,在 `else` 分支中,您可以添加一个针对 `errno` 的判断,以确定错误的具体原因,并根据需要采取相应的措施。

下面是针对您的两个问题的解答和相应的代码修正:

1. 对于 `num_bytes == 0` 的情况,我们直接退出程序,因为没有读取到任何数据,这可能是串口关闭或没有数据可读。

2. 对于读取出错的情况,我们可以根据 `errno` 的值判断错误的具体原因,并据此决定是否退出程序。这样可以使代码更加健壮,能够更好地处理可能的错误情况。

下面是修改后的代码片段:

```c
// 串口读取函数
void read_serial(Config *config) {
    unsigned char buffer[BUFFER_SIZE];
    ssize_t num_bytes;
    int frame_start_detected = 0;
    int recv_index = 0;
    int consecutive_failures = 0; // 记录连续失败的次数
    struct timeval tv;
    fd_set rfds;

    while (1) {
        // 发送查询指令
        send_query(config->serial_fd);
        usleep(150000); // 等待150毫秒

        // 设置超时时间为3秒
        tv.tv_sec = 3;
        tv.tv_usec = 0;
        FD_ZERO(&rfds);
        FD_SET(config->serial_fd, &rfds);

        // 等待串口数据
        int retval = select(config->serial_fd + 1, &rfds, NULL, NULL, &tv);
        if (retval == -1) {
            perror("Error in select");
            exit(EXIT_FAILURE);
        } else if (retval == 0) {
            // 超时,增加连续失败计数器
            consecutive_failures++;
            if (consecutive_failures >= 5) {
                // 连续失败超过5次,发送错误信息到服务器
                send_error_to_server();
                // 退出程序
                exit(EXIT_FAILURE);
            }
            continue;
        } else {
            // 读取串口数据
            num_bytes = read(config->serial_fd, buffer + recv_index, BUFFER_SIZE - recv_index);
            if (num_bytes > 0) {
                // 数据读取成功
                consecutive_failures = 0; // 重置连续失败计数器
                recv_index += num_bytes;
                // 打印接收到的十六进制数据
                printf("\n\nReceived data: ");
                for(int i = 0;i < recv_index; ++i){
                   printf("%02X ",buffer[i]);
                }
                printf("\n");

                // 判断帧头是否检测到
                if (!frame_start_detected) {
                    for (int i = 0; i < recv_index; ++i) {
                        if (buffer[i] == 0xAA) {
                            frame_start_detected = 1;
                            // 移动已接收数据到缓冲区开头
                            memmove(buffer, buffer + i, recv_index - i);
                            recv_index -= i;
                            break;
                        }
                    }
                }
                // 判断是否接收到完整的数据包
                if (frame_start_detected && recv_index >= EXPECTED_PACKET_LENGTH && buffer[recv_index - 1] == 0x55) {
                    // 去除帧头和帧尾后的数据长度
                    int data_length = recv_index - 2;
                    // 进行 CRC 校验,传递数据段给 verifyData 函数
                    if (verifyData(buffer + 1, data_length)) {
                        // 提取温度值并打印
                        float temperature = convertToTemperature(buffer + 1);
                        printf("Temperature: %.1f\n", temperature);
                        // 发送POST请求
                        send_temperature_via_post(temperature);
                    } else {
                        printf("CRC 校验失败\n");
                    }
                    // 清除已处理数据
                    recv_index = 0;
                    frame_start_detected = 0;
                }
            } else if (num_bytes == 0) {
                // 串口关闭或无数据可读
                perror("Serial port closed or no data available");
                exit(EXIT_FAILURE);
            } else {
                // 读取出错
                if (errno == EAGAIN || errno == EWOULDBLOCK) {
                    // 数据暂时不可用,继续下一次循环
                    continue

;
                } else {
                    perror("Error reading from serial port");
                    exit(EXIT_FAILURE);
                }
            }
        }
    }
}
```

这样,当 `num_bytes == 0` 时,表示读取操作未返回任何数据,直接退出程序;当读取出错时,我们根据 `errno` 的值判断错误类型,如果是暂时不可用的错误(如 `EAGAIN` 或 `EWOULDBLOCK`),则继续下一次循环;否则,打印错误信息并退出程序。


细节追问:
很专业,您所回答的:
对于 num_bytes == 0 的情况,我们直接退出程序,因为没有读取到任何数据,这可能是串口关闭或没有数据可读。

这一句中,串口关闭可以理解,如下位机在select明明有数据上来了但这一瞬间串口关掉了,没有读取到任何数据。 但是除开这个特殊情况外还有其它情况吗?我理解明明select 侦测到有数据来了,那么这个数据肯定是num_bytes >= 1,怎么就出现明明就通知有数据就读取到0个数据的逻辑判断上来了呢?我有些不理解,难道这个select模型会出现误通知吗?


终极回答:
您提出了一个很好的问题。

在一般情况下,如果使用 `select` 函数或其他 I/O 多路复用机制,并且它返回了通知有数据可读,那么确实会期望从文件描述符中读取到至少一个字节的数据。这是因为 `select` 函数在通知有数据可读时,文件描述符已经准备好被读取了。

因此,对于 `num_bytes == 0` 的情况,通常不会在正常的 `select` 模型下出现,因为如果 `select` 返回了有数据可读的通知,那么读取操作应该至少读取到一个字节的数据。

然而,这种情况可能会发生在某些特殊情况下,比如:

1. 硬件故障:例如,串口接收缓冲区可能已满,导致无法将数据写入应用程序的缓冲区,从而导致读取操作返回 0 字节。
2. 并发操作:例如,在多线程或多进程环境中,可能会发生竞争条件,导致文件描述符被多个线程或进程同时操作,从而导致某些读取操作返回 0 字节。

虽然这种情况很少发生,并且在大多数情况下,`select` 返回了有数据可读的通知,确实会从文件描述符中读取到至少一个字节的数据。但在编写健壮的程序时,应该考虑到所有可能的情况,并且要有适当的错误处理机制来应对这些情况的发生。

因此,对于 `num_bytes == 0` 的情况,除了串口关闭外,还可能存在其他特殊情况,需要根据实际情况进行适当的处理。

$date = microtime(true);// 返回浮点数,小数点前面是当前时间的时间戳,小数点后为当前时间的微秒
var_dump($date);
// 输出:float(1566897763.0927)



PHP的round函数用于四舍五入浮点数。它的作用是返回最接近一个数字的整数,也可以指定小数点后的位数。例如:

$float = 3.14159;
$rounded = round($float, 2); // 返回 3.14
$rounded = round($float); // 返回 3


要求:timestamp 时间戳 :"timestamp": "1709986011923"        #13位的毫秒数,时间戳(精确到毫秒),当前时间5分钟内请求有效
实现:
cat sendmsg_2.php

php sendmsg_2.php
1709986816.8926         #获取当前Unix时间戳,包括微秒  
1709986816893            #转换为毫秒

Mac下面压缩是zip的,放Freebsd下面怎么解压呢?
安装unzip的方法是:
-->whereis unzip  查找port源
一般是/usr/ports/archivers/unzip
cd /usr/ports/archivers/unzip
make install clean
rehash    ---在不重启服务器的条件使安装了的命令生效
就可以用unzip命令了 。。
然后通过ftp上传PHPWind_GBK_5[1].3.zip
用unzip PHPWind_GBK_5[1].3.zip
在服务器上解压。。

===> Options unchanged
/!\ WARNING /!\

You have security/openssl installed but do not have
DEFAULT_VERSIONS+=ssl=openssl set in your make.conf

===>  License Info-ZIP accepted by the user
===>   unzip-6.0_8 depends on file: /usr/local/sbin/pkg - found
=> unzip60.tar.gz doesn't seem to exist in /usr/ports/distfiles/.
=> Attempting to fetch https://downloads.sourceforge.net/project/infozip/UnZip%206.x%20%28latest%29/UnZip%206.0/unzip60.tar.gz
===>   Generating temporary packing list
install  -s -m 555 /usr/ports/archivers/unzip/work/unzip60/unzip  /usr/ports/archivers/unzip/work/stage/usr/local/bin
cd /usr/ports/archivers/unzip/work/unzip60 &&  install  -s -m 555 funzip unzipsfx /usr/ports/archivers/unzip/work/stage/usr/local/bin
/bin/ln -sf unzip /usr/ports/archivers/unzip/work/stage/usr/local/bin/zipinfo
install  -m 555 /usr/ports/archivers/unzip/work/unzip60/unix/zipgrep /usr/ports/archivers/unzip/work/stage/usr/local/bin
install  -m 444 /usr/ports/archivers/unzip/work/unzip60/man/unzip.1  /usr/ports/archivers/unzip/work/stage/usr/local/share/man/man1
cd /usr/ports/archivers/unzip/work/unzip60/man && install  -m 444 funzip.1 unzipsfx.1 zipgrep.1 zipinfo.1  /usr/ports/archivers/unzip/work/stage/usr/local/share/man/man1
cd /usr/ports/archivers/unzip/work/unzip60 && install  -m 0644 README WHERE /usr/ports/archivers/unzip/work/stage/usr/local/share/doc/unzip
====> Compressing man pages (compress-man)
===>  Installing for unzip-6.0_8
===>  Checking if unzip is already installed
===>   Registering installation for unzip-6.0_8
Installing unzip-6.0_8...
===>  Cleaning for unzip-6.0_8

来自:https://dude6.com/article/182115.html
问题:
php的这段代码,不支持访问http时redirect到https,如:
访问:http://jtgl.beijing.gov.cn/jgj/lszt/659722/660341/index.html
307 Temporary Redirect导到:https://jtgl.beijing.gov.cn/jgj/lszt/659722/660341/index.html

请将该函数修改成能自动导到https并获取到相应body内容:
//发起https的get请求
function https_get($url,$timeout=120){
   $curl = curl_init();
   curl_setopt($curl, CURLOPT_URL, $url);
   curl_setopt($curl, CURLOPT_HEADER, 0);
   curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($curl, CURLOPT_TIMEOUT,$timeout);
   curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);  // 跳过检查                                                                                                                  
   curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);  // 跳过检查                                                                                                                  
   $res = curl_exec($curl);                                                                                                                                                          
   curl_close($curl);                                                                                                                                                                
   return $res;   //返回json对象                                                                                                                                                    
}  

回答:
要在PHP中自动将HTTP请求重定向到HTTPS并获取响应内容,您可以使用curl来检测HTTP响应头中的重定向,然后执行相应的HTTPS请求。以下是修改后的函数示例:

function https_get($url, $timeout = 120) {
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_HEADER, true);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); // 启用重定向跟随

    $response = curl_exec($curl);

    $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
    if ($httpCode == 301 || $httpCode == 302) {
        $matches = array();
        preg_match('/Location:(.*?)\n/', $response, $matches);
        $newUrl = trim(array_pop($matches));

        if (!empty($newUrl)) {
            curl_setopt($curl, CURLOPT_URL, $newUrl);
            $response = curl_exec($curl);
        }
    }

    curl_close($curl);
    return $response;
}

$url = "http://jtgl.beijing.gov.cn/jgj/lszt/659722/660341/index.html";
$response = https_get($url);
echo $response;


php -a 测试是OK的。




问题二:那直接在shell下用curl命令实现上面307的Location转向获取到转向后的内容,用什么参数实现呢?我记得好像是有相应参数的。
是的,您可以使用`curl`命令行工具来获取重定向后的内容。要实现HTTP 307重定向的自动跟随,您可以使用`-L`或`--location`参数,这会让`curl`自动跟随重定向并获取最终的内容。下面是示例:


使用`-L`参数,`curl`将自动处理HTTP 307 Temporary Redirect,并获取最终的内容。

3XX response code


       -L, --location
              (HTTP) If the server reports that the requested page has moved to a different location (indicated with a Location: header and a 3XX response code), this option will make
              curl redo the request on the new place. If used together with -i, --include or -I, --head, headers from all requested pages will be shown. When authentication is used, curl
              only sends its credentials to the initial host. If a redirect takes curl to a different host, it will not be able to intercept the user+password. See also --location-
              trusted on how to change this. You can limit the amount of redirects to follow by using the --max-redirs option.
1、命令行直接打开「控制台」应用程序:/System/Applications/Utilities/Console.app
2、手工打开「控制台」应用程序步骤:使用 Spotlight 搜索:点击屏幕右上角的放大镜图标或按下 Command + 空格键,然后在弹出的搜索栏中输入 "控制台"(Console)。

在搜索结果中,你应该会看到 "控制台" 应用程序的图标。点击它以打开应用程序。

一旦打开 "控制台" 应用程序,你将看到左侧的导航栏,其中包含不同类型的日志。你可以选择 "日志报告" 以查看系统日志文件。
==============================================================================================
崩溃报告(Crash Reports):这些报告通常包含有关应用程序或进程崩溃的信息。如果 WindowServer 或其他进程崩溃,相关信息可能会出现在这些报告中。

Spin报告(Spin Reports):Spin 报告包含关于进程的信息,可能会显示进程卡住的情况。这些报告可能提供一些线索,说明哪个进程可能导致了问题。

日志报告(Log Reports):日志报告通常包含系统和应用程序的日志信息。虽然它们不是系统日志,但可能包含有关 WindowServer 或其他进程活动的记录。

诊断报告(Diagnostics Reports):诊断报告通常是系统生成的详细报告,用于识别和解决问题。你可以查看这些报告以获取更多信息。

请打开这些报告,查看是否有与 WindowServer 或其他进程相关的信息,以便更好地了解问题的根本原因。如果你不确定如何解释报告中的信息或需要进一步的帮助,建议联系 Apple 支持或专业人员进行更详细的故障排除。感谢你的耐心和理解。
系统类型:64 位操作系统, 基于 x64 的处理器
经实践发现得安装:X86的,64位的无效。
下载:vcredist_x86.exe
DownLoadURL: https://download.microsoft.com/download/1/6/5/165255E7-1014-4D0A-B094-B6A430A6BFFC/vcredist_x86.exe
微软官网下载入口:https://www.microsoft.com/zh-cn/download/details.aspx?id=26999

来自:https://zhuanlan.zhihu.com/p/651888193
实际修改二进制步骤:https://www.windows11.pro/1359.html
<span>00000008 行中 FE 下<strong>的 03 值</strong>,如下面的屏幕截图所示。</span>
<p><strong><span>6.</span></strong><span>按</span><strong><span>DEL</span></strong><span>删除</span><strong><span>03</span></strong><span>并键入</span><strong><span>01</span></strong><span>。</span></p>

导出再修改:
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3]
"Settings"=hex:30,00,00,00,fe,ff,ff,ff,7a,f4,00,00,03,00,00,00,3c,00,00,00,3c,\
  00,00,00,00,00,00,00,fc,03,00,00,80,07,00,00,38,04,00,00,78,00,00,00,01,00,\
  00,00



Windows11是一款由微软公司推出的PC操作系统,在该版本中,开发商进行了一系列的更新和优化,那么不少用户在下载win11下载安装之后,应该怎么把任务栏放左边呢?现在通过这篇文章给大家介绍一下。

首先使用键盘快捷键“Win+R”调出运行程序。
在运行中输入“regedit”,回车确定,打开注册表编辑器。
将如下路径复制到注册表路径中“\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3”


然后在右侧找到“settings”,双击打开它。

然后找到“00000008”一行,“FE”一列下的数值,将它改为“00”即可。
点击在新窗口中浏览此图片

这里“00”表示“左边”,“01”表示“上方”,“02表示右边”,“03”表示“底部”。

From:https://g.pconline.com.cn/x/1628/16289115.html

https://answers.microsoft.com/zh-hans/windows/forum/all/%E6%88%91%E5%9C%A8%E6%B3%A8%E5%86%8C%E8%A1%A8/bc7546bf-c353-420d-9386-775255c9e8a2

https://zhuanlan.zhihu.com/p/385038278
在Mac上,软链接(symbolic link)是一种特殊类型的文件,它指向另一个文件或目录的路径。默认情况下,当你使用打包工具(例如tar命令)打包软链接时,会将软链接本身打包进去,而不是它所指向的实际文件。

如果你想要在打包时将软链接解析成实际文件路径并打包实际文件,可以使用-L选项来强制解析软链接。这样,打包工具会将软链接解析成实际文件,并将实际文件打包进去。

下面是使用tar命令打包时解析软链接的示例命令:


这个命令会将/path/to/symlink软链接解析成实际文件,并将实际文件打包到archive.tar.gz中。

另外,如果你想要直接拷贝软链接所指向的原始文件,而不是拷贝软链接本身,可以使用cp命令的-L选项。这样,cp命令会拷贝软链接所指向的实际文件而不是软链接本身。

下面是使用cp命令拷贝软链接指向的原始文件的示例命令:

这个命令会拷贝/path/to/symlink软链接所指向的实际文件到/path/to/destination目录中。

请注意,tar命令和cp命令中的-L选项可能在不同的操作系统和版本中略有不同,请根据你的系统和命令版本来查阅相关文档以确保正确使用。


=========
在 CentOS 7 中,systemctl 会根据服务的名称在 /var/run 目录下的 systemd 子目录创建对应的 PID 文件。具体来说,对于服务名称为 pdfwatcher 的服务,systemctl 会在 /var/run/systemd/ 目录下创建一个名为 pdfwatcher.service 的 PID 文件。

你可以通过以下命令查看该 PID 文件的内容:

bash
Copy code
cat /var/run/systemd/pdfwatcher.service
该文件中只包含一个数字,即 pdfwatcher 服务的进程号。这样,systemctl 就可以根据 PID 文件来跟踪服务的进程,并执行相应的管理和控制操作。

请注意,/var/run 目录通常在系统启动时自动挂载,并用于存储运行时的变量数据和进程相关信息。因此,当服务启动时,systemd 会自动在这个目录下创建 PID 文件。




User
我没有找到对应的pid文件,我的systemctl的service文件是写成这样的,为何没有生成呢?
cat /usr/lib/systemd/system/pdfwatcher.service
# It's not recommended to modify this file in-place, because it
# will be overwritten during upgrades.  If you want to customize,
# the best way is to use the "systemctl edit" command.

[Unit]
Description=pdfwatcher is a real-time monitoring pdf file chmod value is no longer 400 and alarm daemon
After=network.target

[Service]

Type=forking

ExecStart=/usr/local/pdfwatcher/bin/pdfwatcherd -d

ExecStop=/usr/local/pdfwatcher/bin/pdfwatcherd stop

PrivateTmp=true

[Install]
WantedBy=multi-user.target
import cycle not allowed
而且如果项目很大的时候,一个包下面有很多 .go 文件,只提示包与包的循环引用(如上图),是很难定位到哪个 .go 文件和哪个 .go 文件直接进行了循环引用,难以排查。

go-cyclic run --dir  ~/go_learning/src/pdfwatcher.src.cctv.cn
Failed. 1 circular dependence chains were found.

┌---→  /Users/jackXiang/go_learning/src/pdfwatcher.src.cctv.cn/Requests/Request.go
┆                                       ↓
└---     /Users/jackXiang/go_learning/src/pdfwatcher.src.cctv.cn/Loger/Loger.go


安装:
go install github.com/elza2/go-cyclic@latest
go: downloading github.com/elza2/go-cyclic v1.1.0
go: downloading github.com/fatih/color v1.15.0
go: downloading golang.org/x/mod v0.8.0
go: downloading github.com/urfave/cli/v2 v2.24.4
go: downloading github.com/mattn/go-isatty v0.0.17
go: downloading github.com/mattn/go-colorable v0.1.13
go: downloading golang.org/x/sys v0.6.0
go: downloading github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673
go: downloading github.com/cpuguy83/go-md2man/v2 v2.0.2
go: downloading github.com/russross/blackfriday/v2 v2.1.0



来自:https://link.zhihu.com/?target=https%3A//github.com/elza2/go-cyclic
背景:容器中用docker stop  4d393592c6ec ,sameersbn/redmine:5.0.5 的容器会产生如下日志,docker logs 4d393592c6e  #docker stop 4d393592c6ec  会触发下面的退出,而不是臆想的主动退出了,是手工执行出现docker 退出。

2023-05-18 07:52:16,943 WARN received SIGTERM indicating exit request
2023-05-18 07:52:16,943 INFO waiting for unicorn, cron, nginx to die
2023-05-18 07:52:16,945 INFO stopped: nginx (exit status 0)
2023-05-18 07:52:16,946 INFO stopped: cron (terminated by SIGTERM)
2023-05-18 07:52:17,947 INFO stopped: unicorn (exit status 0)

是一个SIGTERM信号,kill -l 发现15) SIGTERM,编号15,才知道是我自己停止的,而不是长时间运行出现自动退出。这个很重要,因为容器的稳定性相当重要。
下面就以这段C代码进行模拟容器的退出并发SIGTERM信号,如下:
test.c


send.c 用于发送SIGTERM 信号给test


SIGTERM : 程序结束信号,与SIGKILL不同的是该信号可以被阻塞和处理。通常用来要求程序自己正常退出。Shell命令kill 默认产生这个信号。
gcc  test.c -o test
gcc  send.c -o send
运行程序:
./test

./send 12345  //12345是test的pid



终端下输入:
kill 12345
也会给test发送SIGTERM 信号。
or kill -15 12345
kill -SIGTERM 12345



来自:https://blog.csdn.net/a379039233/article/details/80715461
More signal:
#kill -l
1) SIGHUP       2) SIGINT       3) SIGQUIT      4) SIGILL       5) SIGTRAP
6) SIGABRT      7) SIGBUS       8) SIGFPE       9) SIGKILL     10) SIGUSR1
11) SIGSEGV     12) SIGUSR2     13) SIGPIPE     14) SIGALRM     15) SIGTERM
16) SIGSTKFLT   17) SIGCHLD     18) SIGCONT     19) SIGSTOP     20) SIGTSTP
21) SIGTTIN     22) SIGTTOU     23) SIGURG      24) SIGXCPU     25) SIGXFSZ
26) SIGVTALRM   27) SIGPROF     28) SIGWINCH    29) SIGIO       30) SIGPWR
31) SIGSYS      34) SIGRTMIN    35) SIGRTMIN+1  36) SIGRTMIN+2  37) SIGRTMIN+3
38) SIGRTMIN+4  39) SIGRTMIN+5  40) SIGRTMIN+6  41) SIGRTMIN+7  42) SIGRTMIN+8
43) SIGRTMIN+9  44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9  56) SIGRTMAX-8  57) SIGRTMAX-7
58) SIGRTMAX-6  59) SIGRTMAX-5  60) SIGRTMAX-4  61) SIGRTMAX-3  62) SIGRTMAX-2
63) SIGRTMAX-1  64) SIGRTMAX
原因
此磁盘已经被其他进程占用。

解决方法
方法1
ps -aux |grep " image(创建的磁盘名称)"
//通过上述命令找到相关进程杀死(该磁盘可能被别人占用,建议询问后在杀)
kill -9 “上述命令查出的进程号”
重新拉虚拟机
方法2
sb.img文件镜像大小制作: qemu-img create -f qcow2 sb.img 50G
启动虚拟机 fdisk -l 查看查看磁盘信息 一般会输出/dev/vda或/dev/vdb信息
mkfs.ext4 /dev/vda 格式化磁盘(分区磁盘,查看本地/document/Newer_enviroment_construct/分区磁盘命令)
新建一个文件夹mkdir /tmp , 并挂载磁盘 mount /dev/vda /tmp
替换原来的disk

实践如下:
ps -aux|grep "win10"
root     1519052  2.3  0.1 883548 92928 ?        Sl   14:51   1:25 /usr/bin/qemu-img convert -f qcow2 -O qcow2 -o compat=1.1,lazy_refcounts /backup/virtImages/win10_bak_10_10_0_119.img /backup/virtImages/win10_bak_10_10_0_168.img


kill -9 1519052


错误如下:
启动域时出错: 内部错误:process exited while connecting to monitor: 2023-05-12T07:49:37.817008Z qemu-kvm: -blockdev {"node-name":"libvirt-2-format","read-only":false,"driver":"qcow2","file":"libvirt-2-storage","backing":null}: Failed to get "write" lock
Is another process using the image [/backup/virtImages/win10_bak_10_10_0_119.img]?

Traceback (most recent call last):
  File "/usr/share/virt-manager/virtManager/asyncjob.py", line 75, in cb_wrapper
    callback(asyncjob, *args, **kwargs)
  File "/usr/share/virt-manager/virtManager/asyncjob.py", line 111, in tmpcb
    callback(*args, **kwargs)
  File "/usr/share/virt-manager/virtManager/object/libvirtobject.py", line 66, in newfn
    ret = fn(self, *args, **kwargs)
  File "/usr/share/virt-manager/virtManager/object/domain.py", line 1280, in startup
    self._backend.create()
  File "/usr/lib64/python3.6/site-packages/libvirt.py", line 1234, in create
    if ret == -1: raise libvirtError ('virDomainCreate() failed', dom=self)
libvirt.libvirtError: 内部错误:process exited while connecting to monitor: 2023-05-12T07:49:37.817008Z qemu-kvm: -blockdev {"node-name":"libvirt-2-format","read-only":false,"driver":"qcow2","file":"libvirt-2-storage","backing":null}: Failed to get "write" lock
Is another process using the image [/backup/virtImages/win10_bak_10_10_0_119.img]?

来自:https://blog.csdn.net/qq_36657175/article/details/124748507
分页: 1/339 第一页 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 下页 最后页 [ 显示模式: 摘要 | 列表 ]