NET CORE 2.1应用程序添加到Linux(ARM)守护进程导致CPU高 [英] .NET CORE 2.1 app added to Linux(ARM) deamon cause CPU high

查看:320
本文介绍了NET CORE 2.1应用程序添加到Linux(ARM)守护进程导致CPU高的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

或:

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

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



今天我想将我的应用添加到 daemon 为了始终运行,这是我的 daemon serivce 文件,位于 / etc / systemd / system

  [Unit] 
Description =用于控制Tcp设备的myApp

[Service]
WorkingDirectory = / home / pi / Desktop / myApp

ExecStart = / usr / local / bin / dotnet myApp.dll
Restart =总是
#如果此服务在10秒钟后重新启动服务崩溃:
RestartSec = 10
SyslogIdentifier = myApp
#用户= pi
[安装]
想要在启用后,开始$ $ target

$ c>通过 systemctl 命令提供的服务,我可以看到该应用通过 top 运行(进程名称为 dotnet ),但是现在CPU很高(对于进程 dotnet )超过100。



关于CPU如何运行的任何想法,有没有办法让我的进程名称保留下来,而不是 dotnet

解决方案

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

  static void Main(string [] args)
{
//我的业务逻辑代码
// balabala
而(true)
Console.ReadLine();
}

这意味着在守护进程模式下, Console.ReadLine ()总是可以读取空间并引起无限循环,这消耗了CPU,我不确定该空间是如何来的,那是.NET CORE错误吗?


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?

解决方案

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?

这篇关于NET CORE 2.1应用程序添加到Linux(ARM)守护进程导致CPU高的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆