.NET CORE 2.1 应用程序添加到 Linux(ARM) 守护进程导致 CPU 高 [英] .NET CORE 2.1 app added to Linux(ARM) deamon cause CPU high
问题描述
我正在使用 RaspberryPi (3B+) Linux ARM IOT 板,其操作系统为 Debian Stretch 9,我的控制台应用程序是在 .NET CORE 2.1 上开发的.
I'm using RaspberryPi (3B+) Linux ARM IOT board which OS is Debian Stretch 9, and my console application is developed on .NET CORE 2.1.
我的应用程序非常简单,只需打开几个到远程服务器的 TCP 连接,在构建我的应用程序后(带有符号 Linux ARM
),我可以看到输出文件包括 myApp
和 myApp.dll
.我已经通过直接命令行完成了很多运行:
My application is quite simple by just open several TCP connections to a remote server, after build my application (with symbol Linux ARM
), I can see the output files include myApp
, and myApp.dll
. I've done lots of run via directly command line:
pi@raspberrypi:~/Desktop/myApp $ ./myApp
或:
pi@raspberrypi:~/Desktop/myApp $ dotnet ./myApp.dll
两者都运行良好,并且通过top
(进程名称为myApp
,而后者为dotnet
)的CPU是全部小于 20.
which both runs well, and the CPU via top
(process name is myApp
, while the latter is dotnet
) are all less than 20.
今天我想将我的应用程序添加到daemon 以一直运行,这是我在/etc/systemd/system<下的daemon serivce 文件/代码>:
Today I want to add my app to daemon for keep runing all the way, this is my daemon serivce file under /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
在enable, start
服务通过systemctl
命令后,我可以看到应用程序正在通过top
运行(进程名称是dotnet
),但现在 CPU 相当高(对于进程 dotnet
)超过 100.
after enable, start
the service via systemctl
command, I can see the app is running via top
(the process name is dotnet
), but now the CPU is quite high (for process dotnet
) which is over 100.
关于 CPU 如何上升的任何想法,有没有办法保留我的进程名称而不是 dotnet
?
Any idea for how the CPU rises, and is there a way to keep my process name back rather than dotnet
?
推荐答案
最后找到原因是Main
中的代码:
Finally I found the cause is the code in Main
:
static void Main(string[] args)
{
//my business logic code
//balabala
while (true)
Console.ReadLine();
}
这意味着在守护进程模式下,Console.ReadLine()
总是可以读取一个空间并导致无限循环,这消耗了 CPU,我不确定这个空间是怎么来的,是.NET 核心错误?
that means in deamon mode, the Console.ReadLine()
always can read a space and cause an infinite loop, which consumed the CPU, I'm not sure how that space coming, is that .NET CORE bug?
这篇关于.NET CORE 2.1 应用程序添加到 Linux(ARM) 守护进程导致 CPU 高的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!