Hi, I'm trying to write a small piece of code that should be capable of getting the command line arguments for a given process. Similar to the ps(1) tool. What I can't figure out is how exactly to use the pr_argv field of the psinfo_t struct... Here's the code:
#include <procfs.h> #include <stdio.h> #include <unistd.h> #include <fcntl.h> int main(int argc, char **argv) { psinfo_t info; int procfd; if((procfd = open(*(argv + 1), O_RDONLY)) == -1) { perror("open"); return -1; } printf("opened: %s\n", *(argv + 1)); if(read(procfd, (char *) &info, sizeof(info)) < 0) { perror("read"); return -1; } printf("arg vector addr: %d\n", info.pr_argv); /* obviously the next line won't work */ printf("cmd line: %s\n", (char *) info.pr_argv); close(procfd); return 0; } so when I execute the code like that: $ ./a.out /proc/690/psinfo I get something like: arg vector addr: 134512240 cmd line: I guess I can't just access what's on that address like that as it's outside my process. Can you tell me how could I do what I want? Yes I know I can use ps(1) but I wanna do it with my little piece of code if possible. 10x -- This message posted from opensolaris.org