Executing built-in functions

Executing built-in functions - received. The errno will be...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Executing built-in functions All built-in functions except printenv are executed by the parent process. Why? we want setenv, cd etc to modify the state of the parent. If they are executed by the child, the changes will go away when the child exits.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Executing printenv Execute printenv in the child process and exit. In this way the output of printenv could be redirected. ret = fork(); if (ret == 0) { if (!strcmp(argument[0],printenv)) { char **p=environ; while (*p!=NULL) { printf(“%s”,*p); p++; } exit(0); }
Background image of page 2
Signals and the Lex Scanner The scanner implemented by lex calls getc() to get the next char for stdin. getc() calls the system call read(). System calls that block will return if a signal is
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: received. The errno will be EINTR. Ctrl-c generates the SIGINT signal. A child that exits will generate SIGCHLD. In any of these signals getc(), will return 1 (EOF) and it will exit. Signals and the Lex Scanner To prevent a system call to be interrupted, use sigaction when setting the signal handler and also set the flag SA_RESTART. SA_RESTART will retry the system call if interrupted by a signal struct sigaction signalAction; signalAction.sa_handler = sigIntHandler; sigemptyset(&signalAction.sa_mask); signalAction.sa_flags = SA_RESTART; int error = sigaction(SIGINT, &signalAction, NULL ); if ( error ) {...
View Full Document

Page1 / 4

Executing built-in functions - received. The errno will be...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online