00001 /*****************************************************************************\ 00002 * * 00003 * Name : zap_process * 00004 * Author : Chris Koeritz * 00005 * * 00006 * Purpose: * 00007 * * 00008 * Whacks a process named on the command line, if possible. * 00009 * * 00010 ******************************************************************************* 00011 * Copyright (c) 2000-$now By Author. This program is free software; you can * 00012 * redistribute it and/or modify it under the terms of the GNU General Public * 00013 * License as published by the Free Software Foundation; either version 2 of * 00014 * the License or (at your option) any later version. This is online at: * 00015 * http://www.fsf.org/copyleft/gpl.html * 00016 * Please send any updates to: fred@gruntose.com * 00017 \*****************************************************************************/ 00018 00019 #include <basis/guards.h> 00020 #include <basis/istring.h> 00021 #include <opsystem/command_line.h> 00022 #include <loggers/console_logger.h> 00023 #include <opsystem/filename.h> 00024 #include <data_struct/static_memory_gremlin.h> 00025 #include <processes/process_control.h> 00026 #include <processes/process_entry.h> 00027 00028 HOOPLE_STARTUP_CODE; 00029 00030 int main(int argc, char *argv[]) 00031 { 00032 console_logger out; 00033 command_line cmds(argc, argv); 00034 if ( (cmds.entries() < 1) 00035 || (cmds.get(0).type() != command_parameter::VALUE) ) { 00036 out.log(cmds.program_name().basename().raw() + " usage:\n" 00037 "this takes a single parameter, which is the name of a program\n" 00038 "to hunt down and eradicate. this will zap the program without\n" 00039 "any warning or any chance for it to save its state."); 00040 return 1; 00041 } 00042 istring program_name = cmds.get(0).text(); 00043 program_name.to_lower(); 00044 process_entry_array processes; 00045 process_control proc_con; 00046 if (!proc_con.query_processes(processes)) 00047 non_continuable_error("procto", "main", "failed to query processes!"); 00048 bool found = false; 00049 bool success = true; 00050 for (int i = 0; i < processes.length(); i++) { 00051 filename path = processes[i].path(); 00052 istring base = path.basename().raw().lower(); 00053 if (base == program_name) { 00054 found = true; 00055 // out.log("would whack this entry:"); 00056 // out.log(processes[i].text_form()); 00057 bool ret = proc_con.zap_process(processes[i]._process_id); 00058 if (ret) out.log(istring(istring::SPRINTF, "Killed process %d [", 00059 processes[i]._process_id) + program_name + istring("]")); 00060 else { 00061 out.log(istring(istring::SPRINTF, "Failed to zap process %d [", 00062 processes[i]._process_id) + program_name + istring("]")); 00063 success = false; 00064 } 00065 } 00066 } 00067 if (!found) 00068 out.log(istring("Could not find the program named ") + program_name); 00069 if (!success) return 123; 00070 else return 0; 00071 } 00072 00073 #ifdef __BUILD_STATIC_APPLICATION__ 00074 // static dependencies found by buildor_gen_deps.sh: 00075 #include <basis/array.cpp> 00076 #include <basis/byte_array.cpp> 00077 #include <basis/callstack_tracker.cpp> 00078 #include <basis/chaos.cpp> 00079 #include <basis/convert_utf.cpp> 00080 #include <basis/definitions.cpp> 00081 #include <basis/earth_time.cpp> 00082 #include <basis/guards.cpp> 00083 #include <basis/istring.cpp> 00084 #include <basis/log_base.cpp> 00085 #include <basis/memory_checker.cpp> 00086 #include <basis/mutex.cpp> 00087 #include <basis/object_base.cpp> 00088 #include <basis/outcome.cpp> 00089 #include <basis/packable.cpp> 00090 #include <basis/portable.cpp> 00091 #include <basis/sequence.cpp> 00092 #include <basis/set.cpp> 00093 #include <basis/utility.cpp> 00094 #include <basis/version_record.cpp> 00095 #include <data_struct/amorph.cpp> 00096 #include <data_struct/bit_vector.cpp> 00097 #include <data_struct/byte_hasher.cpp> 00098 #include <data_struct/configurator.cpp> 00099 #include <data_struct/hash_table.cpp> 00100 #include <data_struct/pointer_hash.cpp> 00101 #include <data_struct/stack.cpp> 00102 #include <data_struct/static_memory_gremlin.cpp> 00103 #include <data_struct/string_hash.cpp> 00104 #include <data_struct/string_hasher.cpp> 00105 #include <data_struct/string_table.cpp> 00106 #include <data_struct/symbol_table.cpp> 00107 #include <data_struct/table_configurator.cpp> 00108 #include <loggers/console_logger.cpp> 00109 #include <loggers/file_logger.cpp> 00110 #include <loggers/locked_logger.cpp> 00111 #include <loggers/null_logger.cpp> 00112 #include <loggers/program_wide_logger.cpp> 00113 #include <opsystem/byte_filer.cpp> 00114 #include <opsystem/command_line.cpp> 00115 #include <opsystem/critical_events.cpp> 00116 #include <opsystem/directory.cpp> 00117 #include <opsystem/filename.cpp> 00118 #include <opsystem/ini_config.cpp> 00119 #include <opsystem/ini_parser.cpp> 00120 #include <opsystem/path_configuration.cpp> 00121 #include <opsystem/rendezvous.cpp> 00122 #include <processes/process_control.cpp> 00123 #include <processes/process_entry.cpp> 00124 #include <textual/byte_format.cpp> 00125 #include <textual/parser_bits.cpp> 00126 #include <textual/string_manipulation.cpp> 00127 #include <textual/tokenizer.cpp> 00128 #endif // __BUILD_STATIC_APPLICATION__ 00129
1.5.1