Path: utzoo!utgpu!watserv1!watmath!att!linac!pacific.mps.ohio-state.edu!zaphod!usc!cs.utexas.edu!execu!sequoia!rpp386!jfh From: jfh@rpp386.cactus.org (John F Haugh II) Newsgroups: comp.bugs.sys5 Subject: Shell Scripts v. Command Options (was: Re: small bug in who(1) of SVR3) Message-ID: <18946@rpp386.cactus.org> Date: 15 Jan 91 14:40:49 GMT References: <18899@rpp386.cactus.org> <1991Jan14.202053.20054@zoo.toronto.edu> Reply-To: jfh@rpp386.cactus.org (John F Haugh II) Organization: Lone Star Cafe and BBS Service Lines: 68 X-Clever-Slogan: Recycle or Die. In article <1991Jan14.202053.20054@zoo.toronto.edu> henry@zoo.toronto.edu (Henry Spencer) writes: >Add up the costs of writing the C code, the costs of maintaining it, the >costs of enhancing it to add the next round of silly "features", and so >forth. Now consider how many times per second "who" gets run, and how >critical its performance is -- i.e., not very many and not very. The >optimization is not worth the price. Studies have shown that the cost of maintaining code is largely independent of the language and depends primarily on the amount of code. A three line change to a C file should be just as easy to maintain as a three line shell script. As for performance, benchmarks will indicate the fork() is an extremely expensive system call. When I was a Pinnacle Systems, one of my jobs was to perform benchmarks on competitors equipment. The average system that I evaluated fork()'d less than 100 times per second, with many well below 30 or 40. A certain 3 letter company's product fork'd about 20 times per second. Script is typescript, started Tue Jan 15 08:28:02 1991 rpp386-> cat fork.c main () { int i; for (i = 0;i 1000;i++) if (fork ()) while (wait (0) != -1) ; else exit (0); } rpp386-> cc -o fork fork.c -O -s fork.c rpp386-> timex ./fork execution complete, exit code = 1 real 14.53 user 0.83 sys 12.72 rpp386-> calc 1000 / 14.53 68.82312456985548 rpp386-> exit Script done Tue Jan 15 08:28:53 1991 >>... fork() and exec() are neither free nor even cheap - shell >>scripts are just not the right answer. > >Odd; we've found that shell scripts are the right answer for an enormous >range of applications. "ls" is a shell script on utzoo (it invokes the >Sun ls with the -1 option). The question is not whether fork() and exec() >are free -- obviously not -- or cheap -- thanks to manufacturer stupidity >and greed, often they aren't -- but whether they are cheap *enough*. The >answer is usually "yes". If you have more than 68 users on your system and it only forks 68 times per second, you are likely to find that shell scripts run pretty damned slow. The command who | cut -d' ' -f1 | sort | pr -6 -l1 will stop being fast *enough* the first time some collection of people start kicking off the other shell scripts the have replaced the other commands on the system. -- John F. Haugh II UUCP: ...!cs.utexas.edu!rpp386!jfh Ma Bell: (512) 832-8832 Domain: jfh@rpp386.cactus.org "While you are here, your wives and girlfriends are dating handsome American movie and TV stars. Stars like Tom Selleck, Bruce Willis, and Bart Simpson."