First off, within my assignment i am looking for the command line arguments of a process. I can access them through the file: /proc/<pid>/cmdline, but where is this information available within the kernel?
We are using version 2.6.19.1
I have been able to print out the pid and name of the program associated with the pid through the pid struct and task_struct information, but we have been asked to dispaly all information which is seen in the formatting of:
ps -e --format "pid args"Any thoughts on how to get the rest of the info within my C file would be appreciated.
My other releated problem potentiall solves the above as i was told that the pid task_struct->comm contains this information, i am doubtful, but hey comm could stand for command line. It retrieved the name from this file, and by the looks of it there could be more information but it is separated by \0 characters i believe.
ex:
less /proc/<pid>/cmdlineresults in:
name^Qpath^Qtty#^Qetc based on the arguments given on running the process.
If the information i recieved is correct, then i need to remove these ^Q which are \0.
if i was dealing with a char[] it would be no problem, but it is a char* which will not allow me to modify it so easily as:
attempt1)
CODE
while(text[i] != EOF)
{
if(text[i] == '\0')
{
printf("*");
text[i] = ' '; //replace \0 with ' '
}
++i;
printf("%d\n",i);
}
attempt2)
CODE
for (temp = text; *temp == '\0'; *(temp++) = ' ')
there have been many other attempts, but modifying the char* is driving me nuts, since it is the \0 character i need to modify.
All suggestions welcome. If i am wrong on the first part, i may not even need this second part.
my test strings were as such:
CODE
char text[] = "some text\0some more text\0";
char *text = "some text\0some more text\0";