If I run a program via rc.local I get no access to the keyboard or monitor with stdin and stdout. How can I get around this?

  • 2
    you can't ... rc.local isn't supposed to run interactively – Jaromanda X Jan 7 at 22:50
  • Interaction with a human interface normally only makes sense after a finished boot up and a full initialized operating system after login. What do you want to do? – Ingo Jan 7 at 23:19
  • I'd like to print debug info to the screen. Also I poll the keyboard (with a SIGIO based interrupt, so I capture non-displayable keys) to control some devices connected to the gpio. – user120300 Jan 8 at 0:42
  • This sounds like something you should do with one of the VCs not being used by the system for logging. You can switch VC's using F-[1-6] (there are six by default); these normally present login prompts but you can configure them to run any foreground process. – goldilocks Jan 31 at 15:06

You could broadcast messages on all user's terminal with wall: that's similar to how shutdown warns all users the system is about to be shut down.

For user input, create a named pipe (e.g. /var/rc_term), give write permissions to everyone and read commands from there. If you need to grab keys which are not specifically sent to the script, see if you can monitor files in /dev/input.


You should use & ampersand for commands in /etc/rc.local, which are not able to daemonize via other flags or not able to be finished in polynomial time...



/usr/bin/qemu-system-x86_64 -hda /opt/ubuntu_11_10.img -net nic -net tap,ifname=tap0,script=no,downscript=no &
/usr/bin/qemu-system-x86_64 -boot d -m 10000 --enable-kvm -cdrom /opt/redhat.iso &
/bin/bash /opt/boot_stage_background_mega_script.sh &
exit 0

The & ampersand - used to fork process and avoid locking on launched command, so rc.local able to exit, and leave other boot sections finishing its job...

  • 1.) It's not "in polynomial time" (since there is no meaningful 'n' value, this does not actually make any sense), it's going to be an arbitrary handful of seconds dependent of the state of the boot process at the time (or it might be a fixed number, but I don't recall seeing it documented anywhere for systemd). – goldilocks Jan 31 at 15:00
  • 2.) exit 1 indicates that the rc.local process has failed. The status code for a process that exited normally (ie., without failing) is zero. – goldilocks Jan 31 at 15:01
  • @goldilocks, thanx, fixed 0 than 0. polynomial time - was a joke, who are know what it is able to understand what I'm talking about.. – Uncle_ampersand Feb 1 at 7:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.