How to find process name in c

John Cowan cowan at marob.masa.com
Thu Oct 18 02:45:22 AEST 1990


In article <2207 at megadon.UUCP>,
	bhoughto at cmdnfs.intel.com (Blair P. Houghton) writes:
>Using this program:
>
>    /* popenpsef.c -- demo popen() */
>    #include <stdio.h>
>    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 at marob.masa.com			(aka ...!hombre!marob!cowan)
			e'osai ko sarji la lojban



More information about the Comp.unix mailing list