The standard way to communicate with a running process through a shell script in linux

Is there a standard linux / unix pattern for communicating with a long running process?

For example, I have several hundred processes written in C ++ and running on different machines and I would like to send them a command such as reload configuration, start, stop, etc. using shell scripts.

+3


source to share


3 answers


Since you also care about remote processes and assume that you can change the source code of all your programs, you may want to consider a way to communicate with them:



  • defining your own little textual protocol and each process is listening on some socket or some named pipe. You probably need some sort of muxed syscall like poll

  • use existing libraries and tools like MPI , Corba , or possibly D-Bus or ONC / RPC / XDR

  • modify your application config files and have signal conventions eg. catch SIGHUP

    to reload the configuration, and SIGTERM

    to terminate it legally (but there is no way to send a signal remotely, you need to, for example, execute the ssh

    some command kill

    ).

+1


source


Signals.



+6


source


If you are trying to initiate simple actions such as the start / stop / reload configuration as you described, the most common method is using signals .

From your shell script, you can use a command kill

to send a specific signal to a specific process. Within your process, you must implement one or more signal handlers. A signal handler registers to receive one or more signals using the signal()

or function sigaction()

.

Normal is SIGHUP

used to trigger a configuration reload. SIGSTOP

and SIGCONT

may be suitable for suspension and resumption.

man 7 signal

will show you a complete list of available signals to choose from.


If you need to invoke more complex actions, you can create a named pipe. Ask your process to create a pipe and from a shell script, it's simple echo

.

+2


source







All Articles