Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <dirent.h> // DIR
- #include <string>
- #include <iostream>
- using namespace std;
- //proc/pid/cmdline
- int main(int argc, char* argv[])
- {
- DIR* proc;// /proc
- FILE *fd ;
- //char cmdline[128];
- string cmdline;
- char *arg = 0; //Lecture cmdline dans le pid proc/pid/cmdline
- size_t argsize = 0;
- struct dirent *ent;
- proc = opendir("/proc");
- while ((ent = readdir(proc)))
- {
- if ((*ent->d_name>'0') && (*ent->d_name<='9')) //numerique ,est un pid
- {
- cout <<"PID NUM="<< ent->d_name<<endl;
- //sprintf(cmdline, "/proc/%s/cmdline", ent->d_name);//cmdline
- cmdline+="/proc/"+string (ent->d_name)+"/cmdline";
- cout <<"cmdline = "<<cmdline<<endl;
- fd = fopen(cmdline.c_str(), "r");//ouvrur cmdline dans le pid
- if (fd == NULL) {cout <<"cmdline Error"<<endl;}
- else {
- while(getdelim(&arg, &argsize, '\0', fd) != -1){
- cout<<'\t'<<" cmdline ="<<arg<<endl;
- }
- }
- if (fd!=NULL) {fclose (fd);};//fermer file descriptor cmdline
- }
- cmdline.clear();
- }
- closedir(proc);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement