programme, die auf ein user laufen zu ermitteln.
Code: Alles auswählen
string app_list(int zeile)
{
string befehl_app_anzahl; // Befehl um die app_anzahl von browser zu bekommen.
int anzahl_app; // Die App_anzahl wird in dieser Variante gespeichert.
string login_name = getlogin(); //login_name zu ermitteln.
string befehl_tail = " -o comm --no-headers";
befehl_app_anzahl = "ps -u ";
befehl_app_anzahl = befehl_app_anzahl + login_name;
befehl_app_anzahl = befehl_app_anzahl + befehl_tail;
anzahl_app = user_app_anzahl();
string app_names [anzahl_app]; // Die Namen aller Applikationen werden in diesem Array gespeichert.
int i=1;
FILE *fp;
char line[30]; Definieren ein Buffer
//Speichert jeder Zeile im Array lwpid.
fp = popen(befehl_app_anzahl.c_str(), "r");
while (fgets(line, sizeof line, fp))
{
//printf("Value of char line %d is %s", i , line);
app_names[i] = line;
//cout << " Id of thread " << i << " is" << lwpid[i]<< endl;
i++;
}
pclose(fp);
return app_names [anzahl_app];
}
Für den Aufruf in mein programm habe ich :
Code: Alles auswählen
ergebnis = new QLabel ( this);
for(int i=1;i<anzahl;i++)
{
string buf = app_list(i);
std:: string ss(buf);
QString qs(ss.c_str());
ergebnis->setText(qs);
}
bitte Hilfe`e 8hD `e`e