def testInitialization(self): """Tests the __init__ function.""" pid = os.getpid() process_information = process_info.ProcessInfo(pid) self.assertIsNotNone(process_information) with self.assertRaises(IOError): process_info.ProcessInfo(-1)
def testGetUsedMemory(self): """Tests the GetUsedMemory function.""" pid = os.getpid() process_information = process_info.ProcessInfo(pid) used_memory = process_information.GetUsedMemory() self.assertIsNotNone(used_memory)
def __init__(self): """Initializes a single process engine.""" super(SingleProcessEngine, self).__init__() self._current_display_name = '' self._last_status_update_timestamp = 0.0 self._path_spec_extractor = extractors.PathSpecExtractor() self._pid = os.getpid() self._process_information = process_info.ProcessInfo(self._pid) self._processing_configuration = None self._status_update_callback = None
def _RunProcess(self): """Runs the process.""" # Prevent the KeyboardInterrupt being raised inside the process. # This will prevent a process from generating a traceback when interrupted. signal.signal(signal.SIGINT, signal.SIG_IGN) # A SIGTERM signal handler is necessary to make sure IPC is cleaned up # correctly on terminate. signal.signal(signal.SIGTERM, self._SigTermHandler) # A SIGSEGV signal handler is necessary to try to indicate where # worker failed. # WARNING the SIGSEGV handler will deadlock the process on a real segfault. if self._enable_sigsegv_handler: self._original_sigsegv_handler = signal.signal( signal.SIGSEGV, self._SigSegvHandler) self._pid = os.getpid() self._process_information = process_info.ProcessInfo(self._pid) # We need to set the is running status explicitly to True in case # the process completes before the engine is able to determine # the status of the process, such as in the unit tests. self._status_is_running = True # Logging needs to be configured before the first output otherwise we # mess up the logging of the parent process. loggers.ConfigureLogging( debug_output=self._debug_output, filename=self._log_filename, quiet_mode=self._quiet_mode) logger.debug('Process: {0!s} (PID: {1:d}) started'.format( self._name, self._pid)) self._StartProcessStatusRPCServer() logger.debug('Process: {0!s} (PID: {1:d}) enter main'.format( self._name, self._pid)) self._Main() logger.debug('Process: {0!s} (PID: {1:d}) exit main'.format( self._name, self._pid)) self._StopProcessStatusRPCServer() logger.debug('Process: {0!s} (PID: {1:d}) stopped'.format( self._name, self._pid)) # Make sure log files are cleanly closed. logging.shutdown() self._status_is_running = False
def _StartMonitoringProcess(self, process): """Starts monitoring a process. Args: process (MultiProcessBaseProcess): process. Raises: IOError: if the RPC client cannot connect to the server. KeyError: if the process is not registered with the engine or if the process is already being monitored. OSError: if the RPC client cannot connect to the server. ValueError: if the process is missing. """ if process is None: raise ValueError('Missing process.') pid = process.pid if pid in self._process_information_per_pid: raise KeyError( 'Already monitoring process (PID: {0:d}).'.format(pid)) if pid in self._rpc_clients_per_pid: raise KeyError( 'RPC client (PID: {0:d}) already exists'.format(pid)) rpc_client = plaso_xmlrpc.XMLProcessStatusRPCClient() # Make sure that a worker process has started its RPC server. # The RPC port will be 0 if no server is available. rpc_port = process.rpc_port.value time_waited_for_process = 0.0 while not rpc_port: time.sleep(0.1) rpc_port = process.rpc_port.value time_waited_for_process += 0.1 if time_waited_for_process >= self._RPC_SERVER_TIMEOUT: raise IOError( 'RPC client unable to determine server (PID: {0:d}) port.'.format( pid)) hostname = 'localhost' if not rpc_client.Open(hostname, rpc_port): raise IOError(( 'RPC client unable to connect to server (PID: {0:d}) ' 'http://{1:s}:{2:d}').format(pid, hostname, rpc_port)) self._rpc_clients_per_pid[pid] = rpc_client self._process_information_per_pid[pid] = process_info.ProcessInfo(pid)
def __init__(self): """Initializes a multi-process engine.""" super(MultiProcessEngine, self).__init__() self._name = u'Main' self._pid = os.getpid() self._process_information = process_info.ProcessInfo(self._pid) self._process_information_per_pid = {} self._processes_per_pid = {} self._rpc_clients_per_pid = {} self._rpc_errors_per_pid = {} self._status_update_active = False self._status_update_callback = None self._status_update_thread = None self._storage_writer = None self._worker_memory_limit = definitions.DEFAULT_WORKER_MEMORY_LIMIT
def _StartMonitoringProcess(self, pid): """Starts monitoring a process. Args: pid (int): process identifier (PID). Raises: KeyError: if the process is not registered with the engine or if the process is already being monitored. IOError: if the RPC client cannot connect to the server. """ self._RaiseIfNotRegistered(pid) if pid in self._process_information_per_pid: raise KeyError( u'Process (PID: {0:d}) already in monitoring list.'.format( pid)) if pid in self._rpc_clients_per_pid: raise KeyError( u'RPC client (PID: {0:d}) already exists'.format(pid)) process = self._processes_per_pid[pid] rpc_client = plaso_xmlrpc.XMLProcessStatusRPCClient() # Make sure that a process has started its RPC server. RPC port will # be 0 if no server is available. rpc_port = process.rpc_port.value time_waited_for_process = 0.0 while not rpc_port: time.sleep(0.1) rpc_port = process.rpc_port.value time_waited_for_process += 0.1 if time_waited_for_process >= self._RPC_SERVER_TIMEOUT: raise IOError( u'RPC client unable to determine server (PID: {0:d}) port.' .format(pid)) hostname = u'localhost' if not rpc_client.Open(hostname, rpc_port): raise IOError( (u'RPC client unable to connect to server (PID: {0:d}) ' u'http://{1:s}:{2:d}').format(pid, hostname, rpc_port)) self._rpc_clients_per_pid[pid] = rpc_client self._process_information_per_pid[pid] = process_info.ProcessInfo(pid)
def __init__(self): """Initializes a single process engine.""" super(SingleProcessEngine, self).__init__() self._current_display_name = '' self._extraction_worker = None self._file_system_cache = [] self._number_of_consumed_sources = 0 self._parsers_counter = None self._path_spec_extractor = extractors.PathSpecExtractor() self._pid = os.getpid() self._process_information = process_info.ProcessInfo(self._pid) self._processing_configuration = None self._resolver_context = None self._status = definitions.STATUS_INDICATOR_IDLE self._status_update_active = False self._status_update_callback = None self._status_update_thread = None self._storage_writer = None
def testInitialization(self): """Tests the initialization.""" pid = os.getpid() process_information = process_info.ProcessInfo(pid) self.assertIsNotNone(process_information)