Answer the question
In order to leave comments, you need to log in
How to start/restart a process on linux (centos)?
Good afternoon.
- There is a simple socket server written in C#.
- Launched via Mono environment + IML / .NET assembly (>mono server.exe)
- via admin panel (webmin) I want to make two buttons, "RUN" / "STOP" (or one "RESTART")
The launch is understandable, but how to find the ID I don't understand the process to stop (for example, in sh script).
How to quickly do this?
Answer the question
In order to leave comments, you need to log in
There is a pidof utility for Linux that returns the process id by name.
Also, one of the common practices is to save the process id when it starts in a permanent file /var/run/myprogram.pid
If Centos 7, then SystemD manages the processes, you can write your own Unit for it.
An example of a wrapper for starting a process while saving the id in a file:
#!/bin/bash
/path/to/mono /path/to/server.exe &
echo $! >/var/run/mono_server.pid
# ps axww | grep myprogram | grep -v grep | awk '{print $1}'
You can register your server as a service by putting the script in init.d , and using the daemon from libslack to start/stop, plus there will be an auto-restart when it crashes.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question