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(); }
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
Just add a sleep
command.
while true; do sleep 600; done
will sleep for 10 minutes between loops.
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
read
or cat
incorrectly consume from that...
– thrig
May 19 '17 at 14:11
tail -f /an/existing/regular/file >/dev/null
: this 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)
– Olivier Dulac
May 19 '17 at 14:19
tail -f <<EOF
to be a tiny bit more portable ^^ (you already have +1 from me anyway)
– Olivier Dulac
May 19 '17 at 14:29
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)
read()
system call per second though.
– Stéphane Chazelas
May 19 '17 at 16:28
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
sleep 999999999
. It saves the hassle of a shell script and forking another process every ten minutes. :) – ilkkachu May 19 '17 at 14:14sleep
builtin ofksh93
, but not that ofmksh
. – Stéphane Chazelas May 19 '17 at 16:25