pargs from within your program

I was asked how to obtain the arguments to a program other than your own without executing the command pargs. The answer is procfs. psinfo has a field,pr_psargs, containing the first 80 characters of the command line arguments. But some programs, especially java programs, have more than 80 characters. It so happens that psinfo contains pr_argv which contains the address of a vector of pointers to the character string for each argument. This address is in the address space of the application! So we have to pread from the /proc/pid/as to load the vector of addresses and then pread the character strings for each command line argument. It adds to the complexity as we have to read different amounts depending on whether the target application is 32 or 64 bit.

My sample code is here

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

user12610965

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today