1

Is there a way to join an interactive session of a process that was ran on boot with /etc/rc.local, or send it "stop" over STDIN on reboot/shutdown and wait for it to end before shutting down?

12
  • 1
    If you launch it in something like screen or tmux you could certainly do that Jul 18, 2017 at 11:31
  • @EricRenouf even if launched at startup? And is there a way to automate the process with, as I said, sending stop to the process over STDIN and wait for it to end before shutting down (I do need the network interface to be still up before the process ends).
    – Jan Novák
    Jul 18, 2017 at 11:40
  • Sure, you can script starting a process inside screen see some examples here and you can send commands later to it like here Jul 18, 2017 at 11:47
  • @EricRenouf But doesn't that have to be from the same session?
    – Jan Novák
    Jul 18, 2017 at 13:27
  • 1
    rc.local has been superseded on many operating systems, several times over on some. It only thus works at all via backwards compatibility shims. Exactly how those backwards compatibility shims work varies, moreover. With several of them rc.local does not even have an interactive session and a controlling terminal. rc.local thus does not work the same everywhere, and you need to be specific about what operating system this question pertains to.
    – JdeBP
    Jul 18, 2017 at 13:31

1 Answer 1

0

As has been explained in comments, you need to “save” the process's stdin somehow. By default, depending on the init system, this may be the console, or /dev/null. To be able to attach to the process, use a screen multiplexer such as Screen or tmux. See also How can I disown a running process and associate it to a new screen shell?

In /etc/rc.local, run something like

screen -S mydaemon -md /usr/local/bin/mydaemon --some-option

To attach to the program interactively, you would then run

screen -S mydaemon -rd

To automatically send keystrokes to the program (see sending text input to a detached screen):

screen -S mydaemon -p 0 -X stuff 'bye^M'
2
  • What's up with the "stuff" in the last one?
    – Jan Novák
    Jul 22, 2017 at 5:15
  • @JanNovák That sends keyboard input to the application, which you requested in the question. Jul 23, 2017 at 15:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .