1 #ifndef PROCESS_CONTROL_CLASS
2 #define PROCESS_CONTROL_CLASS
4 /*****************************************************************************\
6 * Name : process_control *
7 * Author : Chris Koeritz *
9 *******************************************************************************
10 * Copyright (c) 2000-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
18 #include "process_entry.h"
20 #include <basis/contracts.h>
21 #include <mathematics/chaos.h>
22 #include <structures/set.h>
27 class process_entry_array;
28 class process_implementation_hider;
30 //! Provides a bridge to the operating system for information on processes.
32 This object can query the operating system for the current set of processes
33 or zap a particular process of interest.
36 class process_control : public virtual basis::nameable
40 virtual ~process_control();
42 DEFINE_CLASS_NAME("process_control");
44 bool healthy() const { return _healthy; }
45 //!< returns true if this object should be functional.
46 /*!< if it failed to construct properly, this returns false. usually a
47 failure indicates that a required dynamic library is missing, such as
48 "psapi.dll" on win32. */
50 process_entry query_process(basis::un_int to_query);
51 //!< returns the information for just one process.
53 bool query_processes(process_entry_array &to_fill);
54 //!< finds the processes that are running and drops them into "to_fill".
56 bool zap_process(basis::un_int to_zap);
57 //!< preemptively zaps the process "to_zap".
58 /*!< this does not invoke any friendly graceful shut down process, but
59 merely terminates it if possible. */
61 static bool find_process_in_list(const process_entry_array &processes,
62 const basis::astring &app_name, structures::int_set &pids);
63 //!< uses a pre-existing list of "processes" to search for the "app_name".
64 /*!< if the process is found, true is returned and the "pids" are set to
65 all entries matching the process name. note that this is an approximate
66 match for some OSes that have a brain damaged process lister (such as
67 ms-windows); they have programs listed under incomplete names in some
70 void sort_by_name(process_entry_array &to_sort);
71 // sorts the list by process name.
72 void sort_by_pid(process_entry_array &to_sort);
73 // sorts the list by process id.
76 process_implementation_hider *_ptrs; //!< our OS baggage.
78 mathematics::chaos *_rando; //!< used for process list.
80 bool _use_psapi; //!< true if we should be using the PSAPI on NT and family.
82 bool _healthy; //!< true if construction succeeded.
85 bool get_processes_with_ps(process_entry_array &to_fill);
86 //!< asks the ps program what processes exist.
88 // fill in our function pointers to access the kernel functions appropriate
89 // for either NT (psapi) or 9x (toolhelp).
90 bool initialize_psapi_support();
91 bool initialize_toolhelp_support();
93 bool get_processes_with_psapi(process_entry_array &to_fill);
94 //!< uses the PSAPI support for windows NT 4 (or earlier?).
95 bool get_processes_with_toolhelp(process_entry_array &to_fill);
96 //!< uses the toolhelp support for windows 9x, ME, 2000.
102 #endif // outer guard.