Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!wuarchive!julius.cs.uiuc.edu!apple!altos!megadon!clp From: cowan@marob.masa.com (John Cowan) Newsgroups: comp.unix Subject: Re: How to find process name in c Message-ID: <2223@megadon.UUCP> Date: 17 Oct 90 16:45:22 GMT References: <2207@megadon.UUCP> Sender: clp@megadon.UUCP Organization: The Logical Language Group, Inc. Lines: 63 Approved: clp@megadon.UUCP In article <2207@megadon.UUCP>, bhoughto@cmdnfs.intel.com (Blair P. Houghton) writes: >Using this program: > > /* popenpsef.c -- demo popen() */ > #include > main() > { > FILE *pp; > char line[BUFSIZ]; > > pp = popen("ps -ef","r"); > > while ( fgets(line, sizeof line, pp) != NULL ) > fputs(line,stdout); > } > >and doing 'time ps -ef' vs. 'time popenpsef' a few times, >I get these results: > > time ps -ef > 0.2u 0.3s 0:00 206% 70+427k 0+0io 0pf+0w > 0.2u 0.3s 0:00 70% 69+435k 0+0io 0pf+0w > 0.2u 0.3s 0:00 206% 71+444k 0+0io 0pf+0w > > time popenpsef > 0.0u 0.0s 0:00 8% 6+15k 0+0io 0pf+0w > 0.0u 0.0s 0:00 9% 7+18k 0+0io 0pf+0w > 0.0u 0.0s 0:00 5% 6+14k 0+0io 0pf+0w [bogus conclusion about 'ps' behavior deleted] Since your code above doesn't do a pclose(), it doesn't bother to wait for the embedded ps command to terminate. Therefore, the timing statistics refer only to the run time of "popenpsef" itself only. Here's the statistics as generated on my system. BTW, timing was done using the built-in command of the csh, which seems (by the output format) to be what you used as well. time ps -ef >/dev/null 0.2u 0.2s 0:01 30% 0.1u 0.2s 0:01 32% 0.2u 0.2s 0:00 32% 0.2u 0.2s 0:01 30% time popenpsef > /dev/null 0.0u 0.1s 0:01 6% 0.0u 0.1s 0:00 10% 0.0u 0.1s 0:00 6% 0.0u 0.1s 0:01 8% time popenpsef2 >/dev/null 0.2u 0.3s 0:00 46% 0.2u 0.4s 0:00 52% 0.2u 0.4s 0:01 54% 0.2u 0.4s 0:01 58% where popenpsef is your original code, and popenpsef2 inserts a "pclose(pp)" at the end of the program. I ran this on a '386-based Xenix System V box. -- cowan@marob.masa.com (aka ...!hombre!marob!cowan) e'osai ko sarji la lojban