get process ID
Hi all,
can anyone tell me how do i get(using coding) a pid of the process that is running when i know only the name of the process.... i.e. can some gimme a ready code to find the pid of the process by its name... ? thanks.. :) |
have you considered pgrep?
|
Look at the source code for 'pidof'. It takes a name and returns a PID.
|
ps ux | awk '/name/ && !/awk/ {print $2}'
where name is the name of the process. you can change the ps params this is set to get the processes you own that are running EDIT: not sure what you mean by coding? shell scripting? C code? .. etc? |
wow.. thanks a lot for all replies..:)
i don know much about pgrep.. but i need a C code..... its fine if it directly works on the command line.. with some pipe of grepping.. so that i can use that in the C code inside a system() function....EG: system("ps ux | awk '/name/ && !/awk/ {print $2}'");.... what i need is the PID of the process when the process name is known.... thanks again.... |
|
thanks osor :)the source is too good.. but also too complex and big...
how can i get a simple piece of code.. to do this job... i.e. to return the pid when i give the input as process name ??? or is this possible to get the output in the console to have inside the C program.... below i have a code to do this job !!! but it is hanging in the while loop.... dunno why ..can u tellme what is wrong in the program.... Code:
/**************************************************************************** |
Quote:
As a general advice, when posting in this forum a question where the programming language matters, do not hesitate to make it clear in the posting text, or better, show it in the thread title. eg: "Get process ID [C, C++]" That would benefit to everyone, you, the people providing answers and the people browsing/searching the forum. |
If its not getting to "searching"
then your continue statements must be being executing. Try focusing your attention there to see if that is the cause. use more printfs etc or better yet use gdb to step through the code and see where the problem is. |
thanks for all replies and suggestions...:).i got this code working fine.... had made a mistake while defining the xrealloc() funciton....and typecasting that while calling...:)
|
pidof is the symlink to /usr/bin/killall
Code:
It sends a signal to all processes except the processes in its own session, so it won’t kill the shell that is running the script it was called from. Why is that ? |
Quote:
|
/sbin/pidof -> killall5
where killall5 is as /sbin/killall5 |
Quote:
P.S. By terminal, I assume you mean a tty terminal, not an xterm. |
Executing that all the sessions including the session from which i do execute the killall5 is getting terminated.
I could not relate the behaviour the action being done when i execute the command! Thank you very much ! :) |
All times are GMT -5. The time now is 09:54 PM. |