'How to create PID file from ASP.NET Core application under Linux

I wrote an ASP.NET Core application (.NET 5 actually) and run it under Linux as a systemd service (following this Microsoft guide). Then I wanted to monitor this application with monit application. This application requires services to create a PID file so they are easily discoverable. I decided I'll write a Q&A-style question to help others achieve the same faster.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source