Beispiel #1
0
int main()
{
    int n = max_open_files();
    printf("max number of open files is: %d\n", n);

    return 0;
}
void
port_shutdown_extra_fds (void)
{
	const int top = max_open_files ();
	int f;
	
	for (f = 0; f < top; f++)
		close (f);
}
int my_system_get_child_pid (int flags, const char *shell, const char *command, pid_t *pid)
{
	struct sigaction ignore, save_intr, save_quit, save_stop;
	int status = 0, i;

	ignore.sa_handler = SIG_IGN;
	sigemptyset (&ignore.sa_mask);
	ignore.sa_flags = 0;
    
	sigaction (SIGINT, &ignore, &save_intr);    
	sigaction (SIGQUIT, &ignore, &save_quit);

	if ((*pid = fork ()) < 0){
		fprintf (stderr, "\n\nfork () = -1\n");
		return -1;
	}
	if (*pid == 0){
		const int top = max_open_files ();
		sigaction (SIGINT,  &save_intr, NULL);
		sigaction (SIGQUIT, &save_quit, NULL);

		for (i = 3; i < top; i++)
			close (i);

		*pid = fork ();
		if (*pid == 0){
			if (flags & EXECUTE_AS_SHELL)
				execl (shell, shell, "-c", command, (char *) 0);
			else
				execlp (shell, shell, command, (char *) 0);
			/* See note below for why we use _exit () */
			_exit (127);		/* Exec error */
		} else {
			int status;
			
			waitpid (*pid, &status, 0);
			if (flags & EXECUTE_TEMPFILE)
				unlink (command);
		}
		/* We need to use _exit instead of exit to avoid
		 * calling the atexit handlers (specifically the gdk atexit
		 * handler
		 */
		_exit (0);
	}
	sigaction (SIGINT,  &save_intr, NULL);
	sigaction (SIGQUIT, &save_quit, NULL);
	sigaction (SIGTSTP, &save_stop, NULL);

#ifdef SCO_FLAVOR 
	waitpid(-1, NULL, WNOHANG);
#endif /* SCO_FLAVOR */

	return WEXITSTATUS(status);
}