1 /* 2 Copyright 2021 Northern.tech AS 3 4 This file is part of CFEngine 3 - written and maintained by Northern.tech AS. 5 6 This program is free software; you can redistribute it and/or modify it 7 under the terms of the GNU General Public License as published by the 8 Free Software Foundation; version 3. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 18 19 To the extent this program is licensed as part of the Enterprise 20 versions of CFEngine, the applicable Commercial Open Source License 21 (COSL) may apply to this file if you as a licensee so wish it. See 22 included file COSL.txt. 23 */ 24 25 #ifndef CFENGINE_PROCESS_H 26 #define CFENGINE_PROCESS_H 27 28 #include <platform.h> 29 30 31 /* TODO move to libutils, once windows implementation is merged. */ 32 33 34 #define PROCESS_START_TIME_UNKNOWN ((time_t) 0) 35 36 37 /** 38 * Obtain start time of specified process. 39 * 40 * @return start time (Unix timestamp) of specified process 41 * @return PROCESS_START_TIME_UNKNOWN if start time cannot be determined 42 */ 43 time_t GetProcessStartTime(pid_t pid); 44 45 /** 46 * Gracefully kill the process with pid #pid and start time #process_start_time. 47 * 48 * Under Unix this will send SIGINT, then SIGTERM and then SIGKILL if process 49 * does not exit. 50 * 51 * #process_start_time may be PROCESS_START_TIME_UNKNOWN, which will disable 52 * safety check for killing right process. 53 * 54 * @return true if process was killed successfully, false otherwise. 55 * @return false if killing failed for any reason, or if the PID wasn't 56 * present in the first place. 57 */ 58 bool GracefulTerminate(pid_t pid, time_t process_start_time); 59 60 61 #endif 62