ps
This commit is contained in:
parent
af2bdfb47a
commit
1bdf0defd2
Binary file not shown.
@ -10,6 +10,7 @@
|
||||
#include <readline/readline.h>
|
||||
#include <readline/history.h>
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
|
||||
const int max = 1000;
|
||||
|
||||
@ -188,6 +189,53 @@ void mycp (char **argv){
|
||||
}
|
||||
}
|
||||
|
||||
void myps (char **argv){
|
||||
if (fork() == 0){
|
||||
if (chdir("/proc") != 0){
|
||||
perror("cant open /proc");
|
||||
exit(0);
|
||||
}
|
||||
else{ /*weszlismy w 1 fork do katalogu proc */
|
||||
DIR *d;
|
||||
struct dirent *ent;
|
||||
int i, p;
|
||||
|
||||
if ((d = opendir("/proc")) != NULL){ /*otwieramy proc*/
|
||||
while ((ent = readdir(d)) != NULL){ /*czytamy zawartosc*/
|
||||
char *name = ent->d_name;
|
||||
p=0;
|
||||
for (i=0; i<strlen(name); i++)
|
||||
if (!isdigit(name[i])){
|
||||
p=1;
|
||||
break;
|
||||
}
|
||||
if(p)
|
||||
continue; /*jesli nie jest liczba to idziemy dalej*/
|
||||
|
||||
char *direc;
|
||||
direc = (char*)malloc((strlen(name) + 10) * sizeof(char));
|
||||
direc[0] = '\0';
|
||||
strcat(direc, "./");
|
||||
strcat(direc, name);
|
||||
strcat(direc, "/status"); /*tworzenie sciezki*/
|
||||
if (fork() == 0)
|
||||
execlp("sed", "sed", "-n", "1p", direc, NULL);
|
||||
else
|
||||
wait(NULL);
|
||||
|
||||
if (fork() == 0)
|
||||
execlp("sed", "sed", "-n", "6p", direc, NULL);
|
||||
else
|
||||
wait(NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
else
|
||||
wait(NULL);
|
||||
}
|
||||
|
||||
int main (){
|
||||
int spath = 1, i=0;
|
||||
using_history();
|
||||
@ -252,6 +300,10 @@ int main (){
|
||||
mycp(argv);
|
||||
continue;
|
||||
}
|
||||
else if (!strcmp(argv[0], "showps")){
|
||||
myps(argv);
|
||||
continue;
|
||||
}
|
||||
else if (!strcmp(argv[0], "exit"))
|
||||
break;
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user