#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    245
    Rep Power
    12

    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) ?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Location
    Flint, MI
    Posts
    328
    Rep Power
    13
    There is not such a function. There are a couple of ways to approach this problem.

    The first method is hairy and as non-portable as it gets. You'll need to make a call to whatever function gets a process listing on your operating system. Look into the ps source code to see what that is. Then filter the list to choose only the desired target and get the process id. With process id in hand, kill it with the desired signal. Every operating system has a slightly different call to get the process list, and returns a different structure. To make matters even more fun, the structure changes with each version of the operating system, and many of the components are not documented.

    The second is more portable, but you might as well use the shell code. Open a pipe to ps, again filtering for the matching processed. Get the process ids and kill with the desired signal.
    Clay Dowling
    Lazarus Notes
    Articles and commentary on web development
    http://www.lazarusid.com/notes/
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    Up in the clouds
    Posts
    100
    Rep Power
    14
    Instead of looking at the source for ps, why not look at the source for killall, wouldn't that basically provide you with what you want?

    Mike.

IMN logo majestic logo threadwatch logo seochat tools logo