how get name of process in c/c++

p d's Avatar, Join Date: Apr 2010
p d
Light Poster
hi...
how get name of process and kill once ...
i do it in c# , but i need c++ codes.
thx for your helpping
0
poornaMoksha's Avatar, Join Date: Jan 2011
Ambitious contributor
Since you have not mentioned the OS, so I assume the OS to be Linux.

You should know the PID of the process and then replace the PID in the path

/proc/PID/cmdline

Open the following file and you will get the name of the process and the arguments passed to it.
0
p d's Avatar, Join Date: Apr 2010
p d
Light Poster
thx...
no in widows.
look this :
Code:
#include "conio.h"
#include <iostream>
int main()
{ int i=system("tasklist");
    
    printf("%s",i);
    getch();
return 0;
}
but it is'not useful; because i need array of process name for process
0
poornaMoksha's Avatar, Join Date: Jan 2011
Ambitious contributor
I am not a windows programming expert but still you can look at the following discussions :

http://bytes.com/topic/c/answers/759...-names-windows
http://cboard.cprogramming.com/windo...id-window.html
p d like this
0
p d's Avatar, Join Date: Apr 2010
p d
Light Poster
thx.
ok . find it at last .
TerminateProcess(OpenProcess(PROCESS_TERMINATE,FAL SE,PID),0) //Where PID is a int (or UNIT)
---
now i need too PID number... how get it ?
for example yahoo in my pc is 5328, and chang if closed ; but how the program find it ?
0
p d's Avatar, Join Date: Apr 2010
p d
Light Poster
i find it
thx for all ...
gooooooooood look!