C++ Code of Task manager for Linux

I need someone to give me the code for the following program that could run in linux. The following code is for windows and can be run easily through devc++. I know its not right to ask but at the moment I need it more then anything. Please send me the code over here : k112035@nu.edu.pk THANKS


/// code starts ///

#include<iostream>
#include<windows.h>
#include<conio.h>
#include <tlhelp32.h>

using namespace std;

const HANDLE handle=GetStdHandle(STD_OUTPUT_HANDLE);
void window (int x, int y);
void Gotoxy (int x, int y);

int main(){

int pID,i=0;
SetConsoleTitleA(" Task Manager ");
window(85, 170);
system("cls");
HANDLE hProcessSnap;
HANDLE hProcess;
PROCESSENTRY32 pe32;
DWORD dwPriorityClass;

hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); // We will take a snapshot
if (hProcessSnap != INVALID_HANDLE_VALUE)
{
pe32.dwSize = sizeof(PROCESSENTRY32);

if(Process32First(hProcessSnap, &pe32))
{
SetConsoleTextAttribute(handle,FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY );
Gotoxy(8,6);
cout<<"Process Name";
Gotoxy(47,6);
cout<<"Process ID";
Gotoxy(60,6);
cout<<" Parent Process ID";

SetConsoleTextAttribute(handle, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
do {


Gotoxy(8,8+i);
SetConsoleTextAttribute(handle, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY );

cout<<pe32.szExeFile; // Executable name
Gotoxy(50,8+i);
SetConsoleTextAttribute(handle, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY );

cout<<pe32.th32ProcessID; // Process ID
Gotoxy(65,8+i);
SetConsoleTextAttribute(handle, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY );

cout<<pe32.th32ParentProcessID;

i++;

} while (Process32Next(hProcessSnap, &pe32)); // we take all processes
SetConsoleTextAttribute(handle, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
}

}

Gotoxy(10,10+i);
SetConsoleTextAttribute(handle, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY );
cout<<"Enter Process ID to Kill Process : ";
SetConsoleTextAttribute(handle, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY );
cin>>pID; // Process ID to kill
hProcess = OpenProcess(PROCESS_TERMINATE, 0, pID); // Open process First
TerminateProcess(hProcess,0); // Kils the process
CloseHandle(hProcess); // closing the handler
main();
return EXIT_SUCCESS;

}

void window (int x, int y) // adding a sizeable window screen
{
COORD wsize = {x,y};
SMALL_RECT myrec = {0,0,x-1,y-1};
SetConsoleScreenBufferSize (handle,wsize);
SetConsoleWindowInfo ( handle,TRUE, &myrec);
}

void Gotoxy (int x, int y) // to set the cursor position
{
COORD position = {x,y};
SetConsoleCursorPosition (handle,position);
}


/// code ends ///
Last edited on
I need it more then anything.

You need what?

* The ability to list and kill processes.
or
* A port of your GUI application.
I think he's asking for a port.

To which my answer is NO.
Topic archived. No new replies allowed.