Make CLI use an existing process?

Easiest way to send messages to my linux daemon application? Is it possible that myapp foo barcan cause a callback instead of starting a new process? What is the standard way to communicate with the demon? Is my most sensible choice to stick with PID in /var/runand create a named pipe or socket?

What is the standard way that applications running on the command line communicate with the process of their daemon? I assume it is not possible to request linux to call a callback on input myapp foo bar?

+4
source share
2 answers

What is the standard way that applications running on the command line communicate with the process of their daemon?

There are several ways to do this:

Dropboxes & signals

To store the "pid file" is used a lot of places containing the daemon process ID number: /var/run/<app>/<app>.pid, /var/run/<app>.pid(thanks @Adam Katz for editing) /run/<app>/<app>.pid, /run/<app>.pid(see. Askubuntu: why / var / run has been moved to / the run? ).

When the piddaemon process process is known, the command line program (which runs as a separate process) can interact with the daemon in the following ways:

  • Writing something in a prepared place. This can be a regular file, a database table, or any convenient place read by the server.
  • . - kill, int kill(pid_t pid, int sig);.

: xinetd SIGHUP.

send-a-signal inotify API, . , , , , .

FIFO Pipe

- , , , - . /fifo mkfifo. , , . open() fopen(). /: Perl line-buffered $|=1, .

|, , .

- , mySQL? mysql mysql mysqld , .

mySQL socket. , . , .

UNIX- - . C Linux GNU C.

- - . C select(), , , . GNU C -

NodeJS - Javascript, - , .

"Callbacks"

, linux myapp foo bar?

. , .

myapp foo bar "Linux", Linux, , , .

, , .

( ) Linux - /bin/bash. , bash, bash. , , !

bash. :

: Socket Bash? dtmilano:

Q: , 127.0.0.1:4444, bash , . ?

A:

$exec 3 < > /dev/tcp/127.0.0.1/4444

$cat < & 3

bash , .. :

: TCP-, bash

, exec 5<>"/dev/tcp/${SERVER}/${PORT}" TCP- 5 .

bash TCP. -, Linux-. , William Pursell

bash. * nix. ksh Korn. csh C-. sh. . Wikipedia . !

30 , .

: . . chsh.

, , bash , , , . , . . , ipython, fooobar.com/questions/27471/..., python , , .

+11

, . , - " ?" - , , SO. , , .

- linux?

, - , . . , " ". :

  • Unix - ( , ), idempotent ( ), ; (~ 50 Linux). , . - , " ", " " " ".
  • Unix - IPC ( , ). (, UDP), (, TCP) (, SCTP SPX). ; Unix . , , .
  • IPC IP-, : , . (SysV Posix).
  • , Unix, ( ), , . (SSL/TLS ..).
  • , , , , .. Dbus, , .
  • (AMQP, ZeroMQ, Apache Kafka ..). , - .

, , . , , (Erlang, J2EE...), :)

, myapp foo ?

, . , . : SysV init (telinit - ), firefox ( -no-remote ), :

  • apachectl // , httpd;
  • rndc named, gdc gated ..

- - , , . , :

  • , , ?
  • ?

, .

?

, . , . . .

PID /var/run ?

, . , , , root,/run (/var/run) . non-root (, ~/run/ ) .

, linux myapp foo bar?

" ", , . , , , , . Unix . , , , .. , , .

Erlang node RPC- gen_server: call() . Erlang , node .

, ; Dbus ,

  • Dbus;
  • ,

:

  • ; , ;
  • , , , , , , .

, : " ?" . 20 , , , , , :) .

+3

All Articles