I am trying to get the path which contains the executable of a PID from /proc/pid/cmdline in C. The man page states:
"The command-line arguments appear in this file as a set of strings separated by null bytes ('\0'), with a further null byte after the last string."
My idea (pseudocode):
int main(int argc, char** argv){
// Assume file_path has been initialized
char executable_path[1000];
FILE* file = fopen(file_path, "r");
if(f != NULL){
fscanf("%s", executable_path);
}
return 0;
}
Since I only want the first string from this file(since that is the path containing the executable) and I know for sure that there is a '\0' after the first string, would fscanf be the correct function to use? Will it detect the first '\0' and then store the whole string up to the first '\0' in the executable_path array? (Note: I don't need to extract any of the other strings).
Thanks!