2shell - /* Ignore interactive and job-control signals. */...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 /* Keep track of attributes of the shell. */ #include <sys/types.h> #include <termios.h> #include <unistd.h> pid_t shell_pgid struct termios shell_tmodes int shell_terminal int shell_is_interactive /* Make sure the shell is running interactively as the foreground job before proceeding. */ void init_shell () { /* See if we are running interactively. */ shell_terminal = STDIN_FILENO shell_is_interactive = isatty (shell_terminal) if (shell_is_interactive) { /* Loop until we are in the foreground. */ while (tcgetpgrp (shell_terminal) != (shell_pgid = getpgrp ())) kill (- shell_pgid, SIGTTIN)
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: /* Ignore interactive and job-control signals. */ signal (SIGINT, SIG_IGN) signal (SIGQUIT, SIG_IGN) signal (SIGTSTP, SIG_IGN) signal (SIGTTIN, SIG_IGN) signal (SIGTTOU, SIG_IGN) signal (SIGCHLD, SIG_IGN) /* Put ourselves in our own process group. */ shell_pgid = getpid () if (setpgid (shell_pgid, shell_pgid) < 0) { perror ("Couldn't put the shell in its own process group") exit (1) } /* Grab control of the terminal. */ tcsetpgrp (shell_terminal, shell_pgid) /* Save default terminal attributes for shell. */ tcgetattr (shell_terminal, &shell_tmodes) } }...
View Full Document

This note was uploaded on 02/11/2010 for the course CS pyt278@sin taught by Professor P during the Spring '10 term at Abraham Baldwin Agricultural College.

Ask a homework question - tutors are online