我正在使用 RaspberryPi (3B+)操作系统为Linux ARM IOT板Debian Stretch 9 ,我的控制台应用程序是在 .NET CORE 2.1 上开发的。
我的应用程序非常简单,只需打开几个到远程服务器的 TCP 连接,构建我的应用程序后(使用符号 Linux ARM
),我可以看到输出文件包括 myApp
和 myApp.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/