Пример #1
0
/* ____ SOSTIUIRE QUESTO PROGRAMMA __ */
int main(int argc, char* argv[])
{
    pid_t pid;
    int fd;
    get_info("CALLING PROCESS", 0);

    fd = open("/dev/tty", O_RDWR);
    printf("PGID leader: %ld\n", (long)tcgetpgrp(fd));
    printf("PGID foreground: %ld\n", (long)tcgetsid(0));

    switch (pid = fork()) {

    case -1:
        fprintf(stderr, "Err.(%s) fork() failed\n", strerror(errno));
        exit(EXIT_FAILURE);

    case 0:
        /* Il processo figlio crea una nuova sessione, pertanto PGID e
        SID sono settati al PID del figlio medesimo */
        setsid();
        get_info("CHILD PROCESS", pid);

        exit(EXIT_SUCCESS);

    default:
        waitpid(pid, NULL, 0);
    }

    return (EXIT_SUCCESS);
}
Пример #2
0
int
tcsetpgrp(int fd, pid_t pgrp)
{
	if (tcgetsid(fd) < 0)
		return (-1);
	return (ioctl(fd, TIOCSPGRP, &pgrp));
}
Пример #3
0
void testValues() {
    f = 2;
    int result;
    
    result = tcgetsid(anyint());
    
    //@ assert f == 2;
    //@ assert vacuous: \false;
}
Пример #4
0
int
main ()
{
  int master;
  int slave;

  /* Open a pseudo-terminal, as a master-slave pair.  */
  {
    int res = openpty (&master, &slave, NULL, NULL, NULL);
    if (res != 0)
      {
        fprintf (stderr, "openpty returned %d\n", res);
        return 1;
      }
  }

  /* Create a new session and make it the controlling tty of this session.  */
  {
    int res = login_tty (slave);
    if (res < 0)
      {
        fprintf (stderr, "login_tty failed\n");
        return 1;
      }
  }

  /* From here on, we cannot use stderr for error messages any more.
     If a test fails, just abort.  */

  /* Check that fd = 0, 1, 2 are now open to the controlling terminal for the
     current process and that it is a session of its own.  */
  {
    int fd;
    for (fd = 0; fd < 3; fd++)
      if (!(tcgetpgrp (fd) == getpid ()))
        abort ();
    for (fd = 0; fd < 3; fd++)
      {
        int sid = tcgetsid (fd);
        if (!(sid == -1 ? errno == ENOSYS : sid == getpid ()))
          abort ();
      }
  }

  return 0;
}
Пример #5
0
int main() {
	char cmdline[MAXLINE];
	
	forepid = 0;
	printf("tcgetsid: %d  getsid=%d  tcgetpgrp=%d  myshell pgrp=%d\n", 
		tcgetsid(STDIN_FILENO), getsid(getpid()), tcgetpgrp(STDIN_FILENO), getpgrp());
	
	signal(SIGINT, sigint_handler);
	signal(SIGTSTP, sigtstp_handler);
	signal(SIGCHLD, sigchld_handler);
	signal(SIGALRM, sigalarm_handler);
	initjobs();
	sigsetjmp(env, 1);
	while (1) {	
		printf("myshell> ");
		Fgets(cmdline, MAXLINE, stdin);
		if (feof(stdin))
			exit(0);
		eval(cmdline);
	}
}
Пример #6
0
int main() {
	char cmdline[MAXLINE];
	
	control_block();
	shellpid = getpgrp();
	forepid = 0;
	printf("tcgetsid: %d\ngetsid=%d\ntcgetpgrp=%d\nmyshell pgrp=%d\n", 
		tcgetsid(STDIN_FILENO), getsid(getpid()), tcgetpgrp(STDIN_FILENO), getpgrp());
	
	if (signal(SIGCHLD, SIG_IGN) == SIG_ERR) {
		printf("signal error\n");
		exit(-1);
	}
	initjobs();
	while (1) {	
		printf("myshell> ");
		Fgets(cmdline, MAXLINE, stdin);
		if (feof(stdin))
			exit(0);
		eval(cmdline);
	}
}
Пример #7
0
    r = open(tty_path, O_RDWR | O_NONBLOCK);
    SOL_INT_CHECK_GOTO(r, < 0, end);

    if (r != 0) {
        r = dup2(r, 0);
        SOL_INT_CHECK_GOTO(r, < 0, end);
    }
    r = dup2(STDIN_FILENO, 1);
    SOL_INT_CHECK_GOTO(r, < 0, end);
    r = dup2(STDIN_FILENO, 2);
    SOL_INT_CHECK_GOTO(r, < 0, end);

    fchown(STDIN_FILENO, 0, 0);
    fchmod(STDIN_FILENO, 0620);

    tsid = tcgetsid(STDIN_FILENO);
    if (tsid < 0) {
        r = ioctl(STDIN_FILENO, TIOCSCTTY, 1L);
        SOL_INT_CHECK_GOTO(r, < 0, end);
    }
    r = tcsetpgrp(STDIN_FILENO, pid);
    SOL_INT_CHECK_GOTO(r, < 0, end);

end:
    ioctl(STDIN_FILENO, TIOCSCTTY, 0);
    chdir("/");
    execle(shell, shell, NULL, envp);
}

static void
on_fork(void *data)
Пример #8
0
void runSuccess() {
    tcgetsid(anyint());
}
Пример #9
0
int main(void) {
	printf("We are pid %d\n", getpid());
	printf("The session ID for this terminal %d\n", tcgetsid(0));
	printf("The process group for this terminal %d\n", tcgetpgrp(0));
	exit(EXIT_SUCCESS);
}