Process system signals

@return void
483622
protected function handleSignals(): void
    {
        foreach ([SIGTERM, SIGQUIT, SIGABRT, SIGINT] as $signal) {
            pcntl_signal($signal, function ($signal) {
                $this->terminate($signal);
            });
        }
    }
560890
public function run()
    {
        $this->signal->send($this, 'beginRequest', $this);
        register_shutdown_function([$this, 'end'], 0, false);
        $this->processRequest();
        $this->signal->send($this, 'endRequest', $this);
    }
1193650
public function check() : void {
        $processesInfo = $this->getProcessesInfo();

        foreach($this->processes as $process) {
            foreach($processesInfo as $processInfo) {
                if( Str::startsWith($processInfo->getCommand(), $process->getCommand()) ) {
                    $process->setInfo($processInfo);
                    break 2;
                }
            }
        }

        $this->checked = true;
    }
849176
def clear_signal_handlers(self):
        '''

        '''
        signal.signal(signal.SIGABRT, self.old_sigabrt)
        signal.signal(signal.SIGINT, self.old_sigint)
        signal.signal(signal.SIGPIPE, self.old_sigpipe)
        signal.signal(signal.SIGTERM, self.old_sigterm)
737151
def setup_signal_handlers(self):
        
        LOGGER.debug('Registering signal handlers')
        signal.signal(signal.SIGABRT, self.on_sigabrt)
952046
public function process()
    {
        $logger = $this->getLogger();
        $logger->log("Starting...\n");

        $formatter = $this->createFormatter();
        $parser    = $this->createParser();
        $outputDir = $this->configuration->get('output');
        $sources   = $this->configuration->getSources();
        $count     = count($sources);

        $logger->log("Using {$outputDir} as output directory.\n\n");

        foreach ($sources as $pinocchio) {
            $outputFile = $outputDir . '/' . $pinocchio->getOutputFilename($this->configuration->get('source'));

            $logger->log("Processing {$pinocchio->getTitle()} into {$outputFile}...");

            $formatter->format($parser->parse($pinocchio), $outputFile);

            $logger->log(" Done\n");
        }

        if (!$this->configuration->get('skipIndex')) {
            $logger->log("\nCreating index page at {$outputDir}/index.html.\n");

            $this->createIndexFile($sources, $outputDir);
        }

        $logger->log("\nFinished processing {$count} source files.\n");
    }
464380
public function signalReceived($signal): void
    {
        $form = $this->getForm();
        /** @var Presenter $presenter */
        $presenter = $this->getPresenter();
        $request = $presenter->getRequest();

        switch ($signal) {
            case 'submit':
                $this->processSubmit($form, $request);
                break;
            case 'validate':
                $this->processValidate($form, $request);
                break;
            case 'render':
                $this->processRender($form, $request);
                break;
            default:
                throw new BadSignalException(
                    sprintf('Missing handler for signal "%s" in %s.', $signal, get_class($this))
                );
        }
    }
1026535
public function signal_handler_sigint($signal_number)
	{
		// log that we received an exit request
		$this->received_exit_request(true);

		// kill child processes
		if (self::$parent_pid == getmypid())
		{
			foreach ($this->forked_children as $pid => &$pid_info)
			{
				if ($pid_info['status'] == self::STOPPED)
				{
					continue;
				}

				// tell helpers not to respawn
				if ($pid_info['status'] == self::HELPER)
				{
					$pid_info['respawn'] = false;
				}

				$this->safe_kill($pid, SIGINT, 'requesting child exit for pid: ' . $pid, self::LOG_LEVEL_INFO);
			}

			sleep(1);

			// checking for missed sigchild
			$this->signal_handler_sigchild(SIGCHLD);

			$start_time = time();

			// wait for child processes to go away
			while ($this->forked_children_count > 0)
			{
				if (time() > ($start_time + $this->children_max_timeout))
				{
					foreach ($this->forked_children as $pid => $child)
					{
						if ($child['status'] == self::STOPPED)
						{
							continue;
						}

						$this->safe_kill($pid, SIGKILL, 'force killing child pid: ' . $pid, self::LOG_LEVEL_INFO);

						// stop the child
						$this->forked_children[$pid]['status'] = self::STOPPED;
						$this->forked_children_count--;
					}
				}
				else
				{
					$this->log('waiting ' . ($start_time + $this->children_max_timeout - time()) . ' seconds for ' . $this->forked_children_count . ' children to clean up', self::LOG_LEVEL_INFO);
					sleep(1);
					$this->housekeeping_check();
				}
			}

			// make call back to parent exit function if it exists
			$this->invoke_callback($this->parent_function_exit, $parameters = array(self::$parent_pid, $signal_number), true);
		}
		else
		{
			// invoke child cleanup callback
			if (isset($this->child_bucket))
			{
				$this->invoke_callback($this->child_function_exit[$this->child_bucket], $parameters = array($this->child_bucket), true);
			}
		}

		exit(-1);
	}
234149
protected function registerEventSignals()
    {
        if (!EventLoop::$instance) {
            return;
        }
        foreach (self::$signals as $no => $name) {
            if ($name === 'SIGKILL' || $name == 'SIGSTOP') {
                continue;
            }

            $ev = EventLoop::$instance->signal($no, [$this, 'eventSighandler'], [$no]);
            if (!$ev) {
                $this->log('Cannot event_set for ' . $name . ' signal');
            }
            $ev->add();
            $this->sigEvents[$no] = $ev;
        }
    }
684368
protected function logProcessStandardStreams(): void
    {
        if (!empty($output = $this->process->getIncrementalOutput())) {
            $this->logger->notice('Received data on stdout: {output}', [
                'pid' => $this->processPid,
                'stream' => 'stdout',
                'output' => $output,
            ]);
        }

        if (!empty($errorOutput = $this->process->getIncrementalErrorOutput())) {
            $this->logger->error('Received data on stderr: {output}', [
                'pid' => $this->processPid,
                'stream' => 'stderr',
                'output' => $errorOutput,
            ]);
        }
    }
1072455
protected function process()
    {
        $copyTo = null;

        if (null !== $this->option('install')) {
            $copyTo = $this->_('/usr/local/bin/%name%', $this->getApplication()->getName());
            if (true === is_string($this->option('install'))) {
                $copyTo = $this->option('install');
            }
        }

        $this->getBoxService()->package(null, $copyTo);
    }
1363572
public function run()
    {
        pcntl_signal(SIGINT, array($this, 'stop'));
        pcntl_signal(SIGTERM, array($this, 'stop'));

        $this->running = true;
        while ($this->running) {
            $this->process();
        }
    }
625815
public function processRoute()
    {
        foreach ($this->getList() as $pattern => $route) {

            if (isset($route['status']) && empty($route['status'])) {
                continue;
            }

            $arguments = array();

            if (gplcart_path_match($this->path, $pattern, $arguments)) {
                $this->callController($pattern, $arguments);
            }
        }
    }
1139226
protected function process(): void
    {
        list($commandName, $actionName) = $this->checkArguments();

        $this->options = array_merge(
            $this->extractShortOptionsWithParams(),
            $this->extractShortOptionsVoid(),
            $this->extractLongOptionsWithValues(),
            $this->extractLongOptionsVoid()
        );

        $this->setDomainName($commandName);
        $this->setActionName($actionName);
        $this->analyzeAndSetParams();
    }
461343
def setup_signals():
	
	signal.signal(signal.SIGINT, shutit_util.ctrl_c_signal_handler)
	signal.signal(signal.SIGQUIT, shutit_util.ctrl_quit_signal_handler)
588527
public function process() {
		$this->types = array(
			'errors'     => array(
				'warning'    => _x( 'Warning', 'PHP error level', 'query-monitor' ),
				'notice'     => _x( 'Notice', 'PHP error level', 'query-monitor' ),
				'strict'     => _x( 'Strict', 'PHP error level', 'query-monitor' ),
				'deprecated' => _x( 'Deprecated', 'PHP error level', 'query-monitor' ),
			),
			'suppressed' => array(
				'warning'    => _x( 'Warning (Suppressed)', 'Suppressed PHP error level', 'query-monitor' ),
				'notice'     => _x( 'Notice (Suppressed)', 'Suppressed PHP error level', 'query-monitor' ),
				'strict'     => _x( 'Strict (Suppressed)', 'Suppressed PHP error level', 'query-monitor' ),
				'deprecated' => _x( 'Deprecated (Suppressed)', 'Suppressed PHP error level', 'query-monitor' ),
			),
			'silenced'   => array(
				'warning'    => _x( 'Warning (Silenced)', 'Silenced PHP error level', 'query-monitor' ),
				'notice'     => _x( 'Notice (Silenced)', 'Silenced PHP error level', 'query-monitor' ),
				'strict'     => _x( 'Strict (Silenced)', 'Silenced PHP error level', 'query-monitor' ),
				'deprecated' => _x( 'Deprecated (Silenced)', 'Silenced PHP error level', 'query-monitor' ),
			),
		);
		$components  = array();

		if ( ! empty( $this->data ) && ! empty( $this->data['errors'] ) ) {
			/**
			 * Filters the levels used for reported PHP errors on a per-component basis.
			 *
			 * Error levels can be specified in order to silence certain error levels from
			 * plugins or the current theme. Most commonly, you may wish to use this filter
			 * in order to silence annoying notices from third party plugins that you do not
			 * have control over.
			 *
			 * Silenced errors will still appear in Query Monitor's output, but will not
			 * cause highlighting to appear in the top level admin toolbar.
			 *
			 * For example, to show all errors in the 'foo' plugin except PHP notices use:
			 *
			 *     add_filter( 'qm/collect/php_error_levels', function( array $levels ) {
			 *         $levels['plugin']['foo'] = ( E_ALL & ~E_NOTICE );
			 *         return $levels;
			 *     } );
			 *
			 * Errors from themes, WordPress core, and other components can also be filtered:
			 *
			 *     add_filter( 'qm/collect/php_error_levels', function( array $levels ) {
			 *         $levels['theme']['stylesheet'] = ( E_WARNING & E_USER_WARNING );
			 *         $levels['theme']['template']   = ( E_WARNING & E_USER_WARNING );
			 *         $levels['core']['core']        = ( 0 );
			 *         return $levels;
			 *     } );
			 *
			 * Any component which doesn't have an error level specified via this filter is
			 * assumed to have the default level of `E_ALL`, which shows all errors.
			 *
			 * Valid PHP error level bitmasks are supported for each component, including `0`
			 * to silence all errors from a component. See the PHP documentation on error
			 * reporting for more info: http://php.net/manual/en/function.error-reporting.php
			 *
			 * @since 2.7.0
			 *
			 * @param int[] $levels The error levels used for each component.
			 */
			$levels = apply_filters( 'qm/collect/php_error_levels', array() );

			/**
			 * Controls whether silenced PHP errors are hidden entirely by Query Monitor.
			 *
			 * To hide silenced errors, use:
			 *
			 *     add_filter( 'qm/collect/hide_silenced_php_errors', '__return_true' );
			 *
			 * @since 2.7.0
			 *
			 * @param bool $hide Whether to hide silenced PHP errors. Default false.
			 */
			$this->hide_silenced_php_errors = apply_filters( 'qm/collect/hide_silenced_php_errors', false );

			array_map( array( $this, 'filter_reportable_errors' ), $levels, array_keys( $levels ) );

			foreach ( $this->types as $error_group => $error_types ) {
				foreach ( $error_types as $type => $title ) {
					if ( isset( $this->data[ $error_group ][ $type ] ) ) {
						foreach ( $this->data[ $error_group ][ $type ] as $error ) {
							$component                      = $error['trace']->get_component();
							$components[ $component->name ] = $component->name;
						}
					}
				}
			}
		}

		$this->data['components'] = $components;
	}
842255
function signals() {

  /**
   *  Signal handler.
   */
  function interrupt(signal) {
    this.log.notice('received %s, scheduling shutdown', signal);
    this.shutdown(0, process.exit);
  }

  interrupt = interrupt.bind(this);

  function iterate(signal) {

    /* test environment listener leak */
    if(process.listeners(signal).length) return;

    process.once(signal, function() {
      interrupt(signal);
    })
  }

  ['SIGINT', 'SIGTERM'].forEach(iterate.bind(this));
}