Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   how get name of process in c/c++ (http://www.go4expert.com/forums/process-c-cpp-t27162/)

p d 16Nov2011 14:52

how get name of process in c/c++
 
hi...
how get name of process and kill once ...
i do it in c# , but i need c++ codes.
thx for your helpping

poornaMoksha 16Nov2011 17:00

Re: how get name of process in c/c++
 
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.

p d 16Nov2011 19:47

Re: how get name of process in c/c++
 
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

poornaMoksha 16Nov2011 21:05

Re: how get name of process in c/c++
 
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 17Nov2011 02:03

Re: how get name of process in c/c++
 
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 ?

p d 17Nov2011 02:49

Re: how get name of process in c/c++
 
i find it :D:D
thx for all ...
gooooooooood look!


All times are GMT +5.5. The time now is 05:52.