I want to kill other application similar to
killall command as I know application but can not get
PID at run time.
This has to be done in C code. I know
kill() but it need
Any other way equivalent to killall ?
kill(2) is the system call to send a signal to a process there isn't an equivilent to the
An easy way to do this in C would be to invoke
killall from your C program, using the system(3) library function or possible popen(3).
Alternatively you could read the manual page about the
/proc pseudo file system and search for the command names and find the pids yourself.
man 2 kill man 3 system man 3 popen man 5 proc
To answer the question in the title, no there is no C library that does this matching. Not even libprocps does this.
killall is a simple program that:
Due to it being generic (e.g. it doesn't know what match criteria a user will use beforehand) it has lots of matches. You should know what you want to match already. Your question doesn't really say but it sounds like the name or the command line.
I really caution this entire approach. Processes should be really sure about what other processes they are touching. Name is a terrible match as I can trivially fake that. Also consider you may have two users or two systems using the same name, which process should be killed?
PID files or some other method that records the PID on program commencement is much better because you know exactly which process you are talking about (unless they fork)
As Richard points out above, the killall code is GPL2+ so you can reuse it with the same license. The project moved to gitlab though and is at https://gitlab.com/psmisc/psmisc