LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   C code for killall function (https://www.linuxquestions.org/questions/programming-9/c-code-for-killall-function-78154/)

Linh 08-01-2003 05:49 PM

C code for killall function
 
C code for killall function

What is the C code equivalent for this bash code below
killall smbd

In C code, I can only find this
kill (pid, SIGTERM)

I know how to search for a process name and find its pid to shut down a process, but is there a killall function in C code as in
killall (pid, SIGTERM) ?

Proud 08-01-2003 05:56 PM

Try reading the source of killall, or how to execute shell commands via C.

jemfinch 08-01-2003 06:04 PM

No, there's no syscall to do a killall.

Your best bet is to run through /proc/<digits> and check the first line of the "status" pseudo-file for the name. If it matches, kill that process.

Jeremy

shishir 08-01-2003 11:34 PM

you have to be root to be able to execute the killall command...

you could use pkill <process name>..and if you are the owner of the process, you will be able to kill it....

u may use system() to do this......

hope this helped...if you really want to do this the hard way...what jemfinch says is good enough to satisfy your thirst to write C code


All times are GMT -5. The time now is 08:41 AM.