G
G
GFX Data2018-11-19 10:51:50
linux
GFX Data, 2018-11-19 10:51:50

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

3 answer(s)
R
Roman Sokolov, 2018-11-19
@ShockWave2048

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

C
CityCat4, 2018-11-19
@CityCat4

# ps axww | grep myprogram | grep -v grep | awk '{print $1}'

Why grep -v grep? So that the 'grep myprogram' command itself does not get into the selection

S
shai_hulud, 2018-11-19
@shai_hulud

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 question

Ask a Question

731 491 924 answers to any question