Skip to content
This repository has been archived by the owner on Jun 28, 2019. It is now read-only.

Commit

Permalink
Update ex10-9.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
bskim45 committed Dec 16, 2013
1 parent 4133f16 commit 5772d64
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions exercise/ex10-9.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
10.9

mofaph@gmail.com
2013-5-11
bskim45@gmail.com
2013-12-17
--------------------------------------------------------------------------------

Before the call to execve, the child process opens foo.txt as descriptor 3, redirects stdin to foo.txt,
and then (here is the kicker) closes descriptor 3:

if (Fork() == 0) { /* Child */
/* The Shell may be run these code? */
1. close all the open file descriptor
2. open standard input, and bind it to fd 0
3. open standard output, and bind it to fd 1
4. open standard error output, and bind it to fd 2
fd = Open(‘‘foo.txt’’, O_RDONLY, 0); /* fd == 3 */
Dup2(fd, STDIN_FILENO);
Close(fd);
Execve("fstatcheck", argv, envp);
}

When fstatcheck begins running in the child, there are exactly three open files, corresponding to descriptors
0, 1, and 2, with descriptor 1 redirected to foo.txt.

0 comments on commit 5772d64

Please sign in to comment.