[PATCH] Added to ps ruser,group,rgroup,nice options for -o
Denys Vlasenko
vda.linux at googlemail.com
Fri Jul 3 20:15:41 UTC 2009
On Fri, Jul 3, 2009 at 6:19 PM, David Krakov<krakov at gmail.com> wrote:
> Use FEATURE_PS_ENABLE_ADDITIONAL_COLUMNS to use.
Typo in the patch: ADDITONAL (missing second I).
> Updated POSIX conformance accordingly.
>
> Notice added scanning of /proc/<pid>/status file to procps to obtain
> real user and group ids.
> Tested with and without ENABLE_FEATURE_FAST_TOP (changes reading of
> niceness value of a process in procps).
Apart from whitespace damage, the following is questionable:
+ long niceness;
Why long?
+ PSSCAN_STATUS = 1 << 20,
"Scan /proc/NN/status". This is not what these flags mean.
procps_scan(p, PSSCAN_xxx) means "I want to know value xxx (and you
figure out how to find it)". You need to name them PSSCAN_RUIDGID
and PSSCAN_NICE.
+static long fast_strtol_10(char **endptr)
+{
+ int sign = **endptr == '-' ? -1 : 1;
+
+ if (sign == -1) {
+ ++*endptr;
+ }
+ return (long)fast_strtoul_10(endptr) * sign;
+}
This will perform a multiply. Compiler likely won't figure out
how to optimize it out.
+ while (fgets(buf, sizeof(buf), file)) {
+ char *tp;
+#define SCAN_TWO(str, name1, name2) \
+ if (strncmp(buf, str, sizeof(str)-1) == 0) { \
+ tp = skip_whitespace(buf + sizeof(str)-1); \
+ sscanf(tp, "%u\t%u", &sp->name1, &sp->name2); \
+ continue; \
+ }
+ SCAN_TWO("Uid:" , ruid, uid );
+ SCAN_TWO("Gid:" , rgid, gid );
+#undef SCAN_TWO
+ }
Why do you read uid and gid too? They are already retrieved from
/proc/PID/stat.
Also, you continue scanning even after you got "Gid:". You can stop.
I plan to apply attached modified patch. Can you test it?
Unfortunately it is still big:
function old new delta
procps_scan 1409 1642 +233
out_spec 220 300 +80
func_ruser - 36 +36
func_rgroup - 36 +36
func_group 13 49 +36
func_nice - 29 +29
buffer_fill_and_print 179 196 +17
send_tree 355 360 +5
mkfs_vfat_main 1604 1609 +5
display_speed 85 90 +5
scriptreplay_main 194 197 +3
find_out_spec 55 58 +3
changepath 192 195 +3
sha1_process_block64 497 484 -13
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 10/1 up/down: 491/-13) Total: 478 bytes
--
vda
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 8.patch
Type: text/x-patch
Size: 8717 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20090703/1a70d042/attachment.bin>
More information about the busybox
mailing list