linux - .NET CORE 2.1 应用程序添加到 Linux(ARM) 守护程序导致 CPU 高

标签 linux raspberry-pi .net-core debian

我正在使用 RaspberryPi (3B+)操作系统为Linux ARM IOT板Debian Stretch 9 ,我的控制台应用程序是在 .NET CORE 2.1 上开发的。

我的应用程序非常简单,只需打开几个到远程服务器的 TCP 连接,构建我的应用程序后(使用符号 Linux ARM),我可以看到输出文件包括 myAppmyApp.dll。我已经通过直接命令行完成了很多运行:

pi@raspberrypi:~/Desktop/myApp $ ./myApp

或:

pi@raspberrypi:~/Desktop/myApp $ dotnet ./myApp.dll

两者都运行良好,CPU通过top(进程名称是myApp,而后者是dotnet)是都小于 20

今天我想将我的应用程序添加到daemon 以保持一直运行,这是我的 daemon serivce 文件,位于 /etc/systemd/system:

[Unit]
Description=myApp for controlling Tcp devices

[Service]
WorkingDirectory=/home/pi/Desktop/myApp
# 
ExecStart=/usr/local/bin/dotnet myApp.dll
Restart=always
# Restart service after 10 seconds if this service crashes:
RestartSec=10
SyslogIdentifier=myApp
# User=pi
[Install]
WantedBy=multi-user.target

通过systemctl命令启用,启动服务后,我可以通过top看到应用程序正在运行(进程名称是dotnet),但现在 CPU 非常高(对于进程 dotnet)超过 100。

知道 CPU 是如何上升的吗,有没有办法保留我的进程名称而不是 dotnet

最佳答案

最后我发现原因是Main中的代码:

static void Main(string[] args)
{
    //my business logic code
    //balabala
    while (true)
       Console.ReadLine();
}

这意味着在守护模式下,Console.ReadLine() 总是可以读取一个空格并导致无限循环,这会消耗 CPU,我不确定那个空间是怎么来的,是吗.NET 核心错误?

关于linux - .NET CORE 2.1 应用程序添加到 Linux(ARM) 守护程序导致 CPU 高,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51347125/

相关文章:

python - 在单个文件中提供多个终端命令并一次运行所有命令?

.net-core - .NET Core 2.0 处理多个项目时的 appsettings.json 文件位置

linux - 使用 xargs(并行)时如何获取退出代码

create() 覆盖我的文件

linux - 使用 STLINK 和 Linux 刷新 ST 板

python - 如何修复 Google Cloud Vision 的段错误?

Mysql服务不会再重启了

linux - Qt 的 sysroot 和前缀选项的实际示例是什么

visual-studio-code - 使用 Visual Studio 代码的 AWS Lambda

linux - 将 .Net Core 应用程序部署到 Linux Service Fabric 集群