Results 1 to 8 of 8
Hi guys,
I have a problem when parsing the ps output data. Because there's no unique delimit between two fields(some field use spaces too, args for example), so I look ...
- 09-11-2007 #1Just Joined!
- Join Date
- Aug 2007
- Posts
- 3
How to modify ps output format?
Hi guys,
I have a problem when parsing the ps output data. Because there's no unique delimit between two fields(some field use spaces too, args for example), so I look through the man page to find how it can take a user-define delimit between two fields, but I find nothing.
Someone has any ideas? thank you very much!
- 09-11-2007 #2
Hi,
you haven't mentioned what do you use for parsing ...
If you use bash script, look for shell variable IFS (Internal Field Separator).
S.
- 09-11-2007 #3Just Joined!
- Join Date
- Aug 2007
- Posts
- 3
I'm parsing it in C program, and I get the ps output through a pipe
So I can't set IFS, however,thank you very much
- 09-11-2007 #4
Well, you can read the output line by line. On each line you know the number of fields and you can IMHO suppose, that spaces occur only in the last field (program and arguments). So you can read through the line, until you reach first character of the last field. From that character everything up to a newline character is part of that field.
Anyway, have a look on the output of the command:
Youĺl probably get list of such tripletsCode:strace ps
So ps reads the information from files on proc filesystem ... maybe your program would better parse those files instead of ps. I'm sure you'll find any information you want in /procCode:open("/proc/4209/status", O_RDONLY) = 6 read(6, "Name:\tps\nState:\tR (running)\nSlee"..., 1023) = 621 close(6)
The files there are well parseable, so why to waste your time with let's say rather complex output of ps.
Have a nice day
S.
- 09-12-2007 #5Just Joined!
- Join Date
- Aug 2007
- Posts
- 3
ok, the proc system is more reliable and contain a lot useful infomation.
It's so good advice from you
thank you!
- 09-12-2007 #6
- 09-12-2007 #7Just Joined!
- Join Date
- Sep 2007
- Posts
- 5
Is it really necessary to use C.
Have you tried piping the ps into a gawk script;
really easy to pull fields off of a stream/file with gawk.
The whole idea of UNIX/GNU is least effort, by processing plain text wherever possible.
if you understand all this, then I apologize; sorry for the irrelevance.
- 09-13-2007 #8Linux User
- Join Date
- Aug 2006
- Posts
- 458


Reply With Quote
