I'm looking for a Linux command that does literally nothing, doesn't output anything, but stays alive until ^C.
while true; do; done is not a good solution, because it is CPU intensive.
I'm looking for a Linux command that does literally nothing, doesn't output anything, but stays alive until ^C.
while true; do; done is not a good solution, because it is CPU intensive.
If we look at system calls, there's actually one that does exactly that, pause(2):
pause()causes the calling process (or thread) to sleep until a signal is delivered ...
Of course, then we'd just need a program that uses it. Short of compiling the two-liner C program below, the easiest way is probably with Perl:
perl -MPOSIX -e pause
In C:
#include <unistd.h>
int main(void) { return pause(); }
Just add a sleep command.
while true; do sleep 600; done
will sleep for 10 minutes between loops.
GNU sleep and the sleep builtin of ksh93 (but not mksh) accept any floating point number, not just integers, so you can do this:
sleep infinity
Since you've mentioned ctrl-C I assume that you want to use it in interactive terminal. So you may just wait for input.
$ read
or just use arbitrary other commands which read from stdin like cat. They do "nothing" as long as there is no input.
$ cat >/dev/null
or even better without using stdin:
$ tail -f <<EOF
EOF
you can:
tail -f /an/existing/regular/file >/dev/null
This will not use stdin (as read would) and will sit waiting for new addition to /an/existing/regular/file (doesn't work on some files: tail -f /dev/null will exit immediately. But will work for all regular files. If that file is not growing, the command will eat little cpu)
Not for forever, but there is sleep. You could combine your while loop with sleep - doesn't even seem to tickle the cpus in my gkrellm monitor.
dr01 types faster than I do :) ... so more info - your cpu spiking is because it has to continually process the logic check with no pause between....
while true
do
sleep 100
done
Or as a one-liner
while true; do sleep 100; done