Prozesse in .txt Listen



  • Hi
    Ich möchte ein Programm schreiben, was alle aktuellen Prozesse in einer .txt Datei speichert. Mein Queltext sieht so aus:
    #include <iostream>
    #include <stdio.h>
    #include <conio.h>
    #include <fstream>

    using namespace std;

    int main( int argc, char *argv[])
    {

    fstream f;
    f.open("test2.txt", ios::out);
    f << system("qprocess")<< endl;
    f.close();

    getch();
    system("pause");
    return 0;
    }

    Hat einer eine Idee, wie das funktionieren könnte?



  • ps -ef > active_procs.txt



  • 19freddy92 schrieb:

    Ich möchte ein Programm schreiben, was alle aktuellen Prozesse in einer .txt Datei speichert. ..

    Hat einer eine Idee, wie das funktionieren könnte?

    So:

    #include <fstream>
    #include <iostream>
    #include <string>
    #include <vector>
    
    struct Entry
    {
        friend std::istream& operator>>( std::istream& in, Entry& e );
        std::string m_user;
        std::string m_session;
        int m_kennung;
        int m_pid;
        std::string m_prog;
    };
    std::istream& operator>>( std::istream& in, Entry& e )
    {
        return in >> e.m_user >> e.m_session >> e.m_kennung >> e.m_pid >> e.m_prog;
    }
    
    int main()
    {
        using namespace std;
        vector< Entry > processes;
        {
            const string fname = "process.txt";
            system( ("qprocess >" + fname).c_str() );
            ifstream prc(fname.c_str());
            prc.ignore( 999, '\n' );    // 1.Zeile überlesen
            char prefix;
            for( Entry e; prc >> prefix >> e; ) // am Anfang jeder Zeile '>' überlesen
                processes.push_back( e );
            if( !prc.eof() )
                cerr << "Lesefehler ... " << endl;
        }
        cout << processes.size() << " Prozesse gefunden " << endl;
        // hier liegen die Prozesse in 'processes' vor ..
        return 0;
    }
    

    .. es gibt aber bestimmt auch eine API-Möglichkeit - welches Betriebssystem hast Du?



  • Danke



  • Nur mal so am Rande:

    qprocess zeigt nicht alle Prozesse an

    qprocess * ist vll eher das, was du willst

    da wirds mit sicherheit auch ne winapi-fkt geben, die du direkt aufrufen könntest - konnte aber auf anhieb nichts finden

    bb





  • http://msdn.microsoft.com/en-us/library/ms682489(VS.85).aspx

    Mein vorheriger post hat nicht ganz funktioniert 😛


Log in to reply