.NET CORE 2.1 app added to Linux(ARM) deamon cause

2019-08-27 15:36发布

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.

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

or:

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

which both runs well, and the CPU via top (process name is myApp, while the latter is dotnet) are all less than 20.

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

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.

Any idea for how the CPU rises, and is there a way to keep my process name back rather than dotnet?

1条回答
ら.Afraid
2楼-- · 2019-08-27 15:57

Finally I found the cause is the code in Main:

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

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?

查看更多
登录 后发表回答