[clug] what passes for entertainment...

Sam Couter sam at couter.id.au
Sat Jun 27 08:23:37 GMT 2009


Hal Ashburner <hal.ashburner at gmail.com> wrote:
> How about running a good old fashioned busy loop?
> file busy_loop.c :
> 
> int main (int argc, char **argv)
> {
>     while (1) {}
>     return 0;
> }
> 
> compile with
> $ gcc -Wall busy_loop.c -o busy_loop
> run with
> $ ./busy_loop

Easier:

while (:); do : ; done

> is this different if we update it to sleep every now and then?
> 
> #include <time.h>
> 
> int main (int argc, char **argv)
> {
>     struct timespec timeout;
>     timeout.tv_sec = 0;
>     timeout.tv_nsec = 99999;
>     while(1) {
>         int i;
>         for (i = 1; i < 1000000; ++i) {
>               if ( i % 100000 == 0) {
>                   nanosleep(&timeout, NULL);
>               }
>         }
>     }
>     return 0;
> }

Okay, so I accepted the challenge to brush up on my shell scripting
skills. How about something like:

while true; do for i in $(seq 1 10000); do : ; done; sleep 0.0001; done

This may depend on bash, I don't have a real bourne shell to test with.
-- 
Sam Couter         |  mailto:sam at couter.id.au
OpenPGP fingerprint:  A46B 9BB5 3148 7BEA 1F05  5BD5 8530 03AE DE89 C75C
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
Url : http://lists.samba.org/archive/linux/attachments/20090627/eed8d459/attachment.bin


More information about the linux mailing list