If you want the output printed to console, you are going to have to set that up. There are lots of things started at boot, and they can't all print to console or it would be an interleaved mess. So, just as none of them can hog the foreground without special arrangment, none of them get to hog the console used by the kernel and init (on current versions of Raspbian, init is systemd). The default for anything written to such a process's stdout
or stderr
is systemd's "journal" (i.e., the system log); see "StandardOutput" in man systemd.exec
. That option can be set to "console" (note it must be combined with something else); this may be what you want if it is only a short message every 4 seconds, but it means you will have to start the process via systemd (which is actually the best way to start a boot service anyway, but involves a little more work than rc.local
or cron
).
However, the console used by kernel and init is not the only text terminal.
I'm presuming you are running sans GUI (i.e., "text mode") but not headless (i.e., you have a screen and keyboard). In that case, you could create a shell wrapper and redirect the output to one of the other virtual terminals (VTs). These are where the logins you can find via Ctrl-Alt-F[n] are, where "[n]" is 1-6. Note 2-5 will look the same (except for the tty
number shown), since no kernel or journal output is going there (except for supposedly important warnings).
There's actually more than 6 VTs, but only the first six have a login running. That won't stop you from writing to them but it may be tidier to use tty7
instead. So you could create a shell wrapper like this and put that in rc.local
(or it's own script and start it however you want):
(
exec myloopprogram > /dev/tty7 2&>1
) &
The wrapper here is just the subshell parentheses; this way the subshell will fork to the background (final &
) and then replace itself (exec
) with myloopprogram
, redirecting (>
) all output (2&>1
) to /dev/tty7
. If at boot you then switch to that VT you should see the output.
You could of course just use /dev/tty1
if that's what you really want, or you do not have a keyboard connected. If you don't, but want to use an alternate terminal, you could put the subshell in rc.local
and then afterward:
chvt 7
Which should switch the screen view to to tty7
(though I can't promise it will stay there).