DOC PREVIEW
CMU CS 15213 - Recitation

This preview shows page 1-2-16-17-18-34-35 out of 35 pages.

Save
View full document
Premium Document
Do you want full access? Go Premium and unlock all 35 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Recitation Signaling 15213 S04 Recitation Section A Debug Multiple Processes using GDB Dup2 Signaling L5 Due This Wednesday Debug Multiple Proc s Using GDB attach pid pid the process id of a running process set follow fork mode parent child 2 only work in HP UX and GNU Linux kernel 2 5 60 Fish machines Linux with kernel 2 2 20 15 213 S 04 Attach to a Running Process 1 Run the parent code and create the process tsh Directly in the shell In GDB 2 Get the pid ps e axu grep tsh 3 Run gdb gdb tsh gdb tsh pid 4 Attach to the process 3 gdb attach pid 15 213 S 04 Really that Easy The process must be started outside GDB If you want to debug both the parent process and the child process you need start another gdb in another xterm You have to type in the gdb attach commands fast enough before the process actually finishes You have to modify the source code to let it wait Two methods sleep 10 int gdbf 0 while gdbf For Lab 5 it is more troublesome 4 sdriver runtrace tsh tshref mycat Demo 15 213 S 04 Attach to a Running Process 1 Run runtrace and create the process tsh Directly in the shell In GDB 2 Get the pid ps e axu grep tsh 3 Run gdb gdb tsh gdb tsh pid 4 Attach to the process 5 gdb attach pid 15 213 S 04 Dup2 Basic concepts on file handler File descriptor file table v node table File sharing dup2 Practice problems 6 15 213 S 04 How the Unix Kernel Represents Open Files Two descriptors referencing two distinct open disk files Descriptor 1 stdout points to terminal and descriptor 4 points to open disk file Descriptor table one table per process File A terminal File pos refcnt 1 File B disk File pos 7 File access File size File type Info in stat struct File access File size File type refcnt 1 v node table shared by all processes stdin fd 0 stdout fd 1 stderr fd 2 fd 3 fd 4 Open file table shared by all processes 15 213 S 04 How Processes Share Files A child process inherits its parent s open files Here is the situation immediately after a fork Descriptor tables Open file table shared by all processes Parent s table File A File pos refcnt 2 File size File type File access File size File type 8 File B fd 0 fd 1 fd 2 fd 3 fd 4 refcnt 2 File access Child s table File pos fd 0 fd 1 fd 2 fd 3 fd 4 v node table shared by all processes 15 213 S 04 File Sharing Two distinct descriptors sharing the same disk file through two distinct open file table entries E g Calling open twice with the same filename argument Descriptor table one table per process refcnt 1 File access File size File type File A v node table shared by all processes fd 0 fd 1 fd 2 fd 3 fd 4 Open file table shared by all processes File pos File B File pos refcnt 1 9 15 213 S 04 I O Redirection dup2 oldfd newfd Copies per process descriptor table entry oldfd to entry newfd Descriptor table before dup2 4 1 fd 0 fd 1 fd 0 a fd 1 fd 2 fd 2 fd 3 fd 3 fd 4 10 Descriptor table after dup2 4 1 b fd 4 b b 15 213 S 04 I O Redirection Example Before calling dup2 4 1 stdout descriptor 1 points to a terminal and descriptor 4 points to an open disk file Descriptor table one table per process File A File pos refcnt 1 File B File pos 11 File access File size File type File access File size File type refcnt 1 v node table shared by all processes stdin fd 0 stdout fd 1 stderr fd 2 fd 3 fd 4 Open file table shared by all processes 15 213 S 04 I O Redirection Example cont After calling dup2 4 1 stdout is now redirected to the disk file pointed at by descriptor 4 Descriptor table one table per process File A File pos refcnt 0 File B File pos 12 File access File size File type File access File size File type refcnt 2 v node table shared by all processes fd 0 fd 1 fd 2 fd 3 fd 4 Open file table shared by all processes 15 213 S 04 File Sharing Descriptor table Each process has its own Child inherits from parents File Table set of all open files Shared by all processes Reference count of number of file descriptors pointing to each entry File position V node table 13 Contains information in the stat structure Shared by all processes 15 213 S 04 Problem 11 2 Suppose that foobar txt consists of the 6 ASCII characters foobar Then what is the output of the following program include csapp h int main int fd1 fd2 char c fd1 Open foobar txt O RDONLY 0 fd2 Open foobar txt O RDONLY 0 Read fd1 c 1 Read fd2 c 1 printf c c n c exit 0 14 15 213 S 04 Answer to 11 2 The descriptors fd1 and fd2 each have their own open file table entry so each descriptor has its own file position for foobar txt Thus the read from fd2 reads the first byte of foobar txt and the output is c f and not c o as you might have thought initially 15 15 213 S 04 Problem 11 3 As before suppose foobar txt consists of 6 ASCII characters foobar Then what is the output of the following program include csapp h int main int fd char c fd Open foobar txt O RDONLY 0 if Fork 0 Read fd c 1 exit 0 Wait NULL Read fd c 1 printf c c n c exit 0 16 15 213 S 04 Answer to 11 3 Child inherit s the parent s descriptor table So child and parent share an open file table entry refcount 2 Hence they share a file position c o 17 15 213 S 04 Problem 11 4 How would you use dup2 to redirect standard input to descriptor 5 int dup2 int oldfd int newfd 18 copies descriptor table entry oldfd to descriptor table entry newfd 15 213 S 04 Answer to 11 4 dup2 5 0 or dup2 5 STDIN FILENO 19 15 213 S 04 Problem 11 5 Assuming that foobar txt consists of 6 ASCII characters foobar Then what is the output of the following program include csapp h int main int fd1 fd2 char c fd1 Open foobar txt O RDONLY 0 fd2 Open foobar txt O RDONLY 0 Read fd2 c 1 Dup2 fd2 fd1 Read fd1 c 1 printf c c n c exit 0 20 15 213 S 04 Answer to 11 5 We are redirecting fd1 to fd2 fd1 now points to the same open file table entry as fd2 So the …


View Full Document

CMU CS 15213 - Recitation

Documents in this Course
lecture

lecture

14 pages

lecture

lecture

46 pages

Caches

Caches

9 pages

lecture

lecture

39 pages

Lecture

Lecture

36 pages

Lecture

Lecture

45 pages

Lecture

Lecture

56 pages

lecture

lecture

11 pages

lecture

lecture

9 pages

Lecture

Lecture

36 pages

Lecture

Lecture

37 pages

Exam

Exam

16 pages

Lecture

Lecture

10 pages

Lecture

Lecture

43 pages

Lecture

Lecture

8 pages

Lecture

Lecture

8 pages

Lecture

Lecture

36 pages

Lecture

Lecture

43 pages

Lecture

Lecture

12 pages

Lecture

Lecture

37 pages

Lecture

Lecture

6 pages

Lecture

Lecture

40 pages

coding

coding

2 pages

Exam

Exam

17 pages

Exam

Exam

14 pages

Lecture

Lecture

29 pages

Lecture

Lecture

34 pages

Exam

Exam

11 pages

Lecture

Lecture

9 pages

Lecture

Lecture

37 pages

Lecture

Lecture

36 pages

lecture

lecture

46 pages

Lecture

Lecture

33 pages

Lecture

Lecture

57 pages

Lecture

Lecture

32 pages

Lecture

Lecture

46 pages

Lecture

Lecture

40 pages

Lecture

Lecture

11 pages

Lecture

Lecture

6 pages

Lecture

Lecture

43 pages

Lecture

Lecture

12 pages

Lecture

Lecture

18 pages

Exam

Exam

10 pages

Lecture

Lecture

45 pages

Lecture

Lecture

37 pages

Exam

Exam

24 pages

class09

class09

21 pages

class22

class22

37 pages

class20

class20

30 pages

class27

class27

33 pages

class25

class25

21 pages

class04

class04

31 pages

Lecture

Lecture

59 pages

class01a

class01a

14 pages

class12

class12

45 pages

class29

class29

33 pages

Lecture

Lecture

39 pages

Lecture

Lecture

6 pages

class03

class03

34 pages

lecture

lecture

42 pages

Lecture

Lecture

40 pages

Lecture

Lecture

47 pages

Exam

Exam

19 pages

R06-B

R06-B

25 pages

class17

class17

37 pages

class25

class25

31 pages

Lecture

Lecture

15 pages

final-f06

final-f06

17 pages

Lecture

Lecture

9 pages

lecture

lecture

9 pages

Exam

Exam

15 pages

Lecture

Lecture

22 pages

class11

class11

45 pages

lecture

lecture

50 pages

Linking

Linking

37 pages

Lecture

Lecture

64 pages

Integers

Integers

40 pages

Exam

Exam

11 pages

Lecture

Lecture

37 pages

Lecture

Lecture

44 pages

Lecture

Lecture

37 pages

Lecture

Lecture

9 pages

Lecture

Lecture

37 pages

Lecture

Lecture

45 pages

Final

Final

25 pages

lecture

lecture

9 pages

Lecture

Lecture

30 pages

Lecture

Lecture

16 pages

Final

Final

17 pages

Lecture

Lecture

8 pages

Exam

Exam

11 pages

Lecture

Lecture

47 pages

Lecture

Lecture

9 pages

lecture

lecture

39 pages

Exam

Exam

11 pages

lecture

lecture

41 pages

lecture

lecture

37 pages

Lecture

Lecture

59 pages

Lecture

Lecture

45 pages

Exam 1

Exam 1

18 pages

Lecture

Lecture

41 pages

Lecture

Lecture

32 pages

Lecture

Lecture

30 pages

Lecture

Lecture

9 pages

Lecture

Lecture

9 pages

Lecture

Lecture

15 pages

Lecture

Lecture

11 pages

Lecture

Lecture

9 pages

Lecture

Lecture

34 pages

Lecture

Lecture

40 pages

Lecture

Lecture

4 pages

Lecture

Lecture

46 pages

Lecture

Lecture

8 pages

Lecture

Lecture

65 pages

Lecture

Lecture

38 pages

Lecture

Lecture

35 pages

Lecture

Lecture

8 pages

Lecture

Lecture

34 pages

Lecture

Lecture

8 pages

Exam

Exam

13 pages

Lecture

Lecture

43 pages

Lecture

Lecture

9 pages

Lecture

Lecture

12 pages

Lecture

Lecture

9 pages

Lecture

Lecture

34 pages

Lecture

Lecture

43 pages

Lecture

Lecture

7 pages

Lecture

Lecture

45 pages

Lecture

Lecture

24 pages

Lecture

Lecture

47 pages

Lecture

Lecture

12 pages

Lecture

Lecture

20 pages

Lecture

Lecture

9 pages

Exam

Exam

11 pages

Lecture

Lecture

52 pages

Lecture

Lecture

20 pages

Exam

Exam

11 pages

Lecture

Lecture

35 pages

Lecture

Lecture

47 pages

Lecture

Lecture

18 pages

Lecture

Lecture

30 pages

Lecture

Lecture

59 pages

Lecture

Lecture

37 pages

Lecture

Lecture

22 pages

Lecture

Lecture

35 pages

Exam

Exam

23 pages

Lecture

Lecture

9 pages

Lecture

Lecture

22 pages

class12

class12

32 pages

Lecture

Lecture

8 pages

Lecture

Lecture

39 pages

Lecture

Lecture

44 pages

Lecture

Lecture

38 pages

Lecture

Lecture

69 pages

Lecture

Lecture

41 pages

Lecture

Lecture

12 pages

Lecture

Lecture

52 pages

Lecture

Lecture

59 pages

Lecture

Lecture

39 pages

Lecture

Lecture

83 pages

Lecture

Lecture

59 pages

class01b

class01b

17 pages

Exam

Exam

21 pages

class07

class07

47 pages

Lecture

Lecture

11 pages

Odyssey

Odyssey

18 pages

multicore

multicore

66 pages

Lecture

Lecture

6 pages

lecture

lecture

41 pages

lecture

lecture

55 pages

lecture

lecture

52 pages

lecture

lecture

33 pages

lecture

lecture

46 pages

lecture

lecture

55 pages

lecture

lecture

17 pages

lecture

lecture

49 pages

Exam

Exam

17 pages

lecture

lecture

56 pages

Exam 2

Exam 2

16 pages

Exam 2

Exam 2

16 pages

Notes

Notes

37 pages

Lecture

Lecture

40 pages

Lecture

Lecture

36 pages

Lecture

Lecture

43 pages

Lecture

Lecture

25 pages

Exam

Exam

13 pages

Lecture

Lecture

32 pages

Lecture

Lecture

12 pages

Lecture

Lecture

58 pages

Lecture

Lecture

29 pages

Lecture

Lecture

59 pages

Lecture

Lecture

41 pages

Lecture

Lecture

50 pages

Exam

Exam

17 pages

Lecture

Lecture

29 pages

Lecture

Lecture

44 pages

Lecture

Lecture

41 pages

Lecture

Lecture

52 pages

Lecture

Lecture

40 pages

Lecture

Lecture

33 pages

lecture

lecture

10 pages

Lecture

Lecture

27 pages

Lecture

Lecture

29 pages

Lecture

Lecture

39 pages

Lecture

Lecture

9 pages

Lecture

Lecture

29 pages

Lecture

Lecture

8 pages

Lecture

Lecture

43 pages

Lecture

Lecture

43 pages

Lecture

Lecture

75 pages

Lecture

Lecture

55 pages

Exam

Exam

12 pages

Lecture

Lecture

43 pages

Lecture

Lecture

35 pages

lecture

lecture

36 pages

Exam

Exam

33 pages

lecture

lecture

56 pages

lecture

lecture

64 pages

lecture

lecture

8 pages

Exam

Exam

14 pages

Lecture

Lecture

43 pages

Lecture

Lecture

36 pages

lecture

lecture

56 pages

lecture

lecture

75 pages

lecture

lecture

36 pages

Lecture

Lecture

50 pages

Lecture

Lecture

45 pages

Lecture

Lecture

13 pages

Exam

Exam

23 pages

Lecture

Lecture

10 pages

Lecture

Lecture

48 pages

Lecture

Lecture

83 pages

lecture

lecture

57 pages

Lecture

Lecture

33 pages

Lecture

Lecture

39 pages

Lecture

Lecture

33 pages

lecture

lecture

54 pages

Lecture

Lecture

30 pages

Exam

Exam

13 pages

Lecture

Lecture

36 pages

Lecture

Lecture

40 pages

Exam

Exam

17 pages

Lecture

Lecture

9 pages

Exam

Exam

15 pages

Lecture

Lecture

44 pages

Lecture

Lecture

34 pages

Lecture

Lecture

24 pages

Lecture

Lecture

29 pages

class12

class12

43 pages

lecture

lecture

43 pages

class22

class22

22 pages

R06-B

R06-B

25 pages

class01b

class01b

19 pages

lecture

lecture

29 pages

lab1

lab1

8 pages

Caches

Caches

36 pages

lecture

lecture

55 pages

Lecture,

Lecture,

37 pages

Integers

Integers

40 pages

Linking

Linking

38 pages

lecture

lecture

45 pages

Lecture

Lecture

61 pages

Linking

Linking

33 pages

lecture

lecture

40 pages

lecture

lecture

40 pages

Lecture

Lecture

32 pages

lecture

lecture

48 pages

lecture

lecture

44 pages

Exam

Exam

11 pages

Lecture

Lecture

31 pages

Lecture

Lecture

46 pages

Lecture

Lecture

40 pages

Lecture

Lecture

40 pages

Exam

Exam

12 pages

Lecture

Lecture

42 pages

Lecture

Lecture

36 pages

Lecture

Lecture

45 pages

Lecture

Lecture

41 pages

Lecture

Lecture

13 pages

Lecture

Lecture

35 pages

Lecture

Lecture

20 pages

Final

Final

19 pages

Lecture

Lecture

33 pages

Lecture

Lecture

50 pages

Lecture

Lecture

33 pages

Lecture

Lecture

27 pages

Lecture

Lecture

6 pages

Exam

Exam

15 pages

Lecture

Lecture

24 pages

Lecture

Lecture

23 pages

Lecture

Lecture

43 pages

Lecture

Lecture

32 pages

Lecture

Lecture

52 pages

Lecture

Lecture

37 pages

Lecture

Lecture

36 pages

Lecture

Lecture

34 pages

Lecture

Lecture

40 pages

Lecture

Lecture

15 pages

lecture

lecture

21 pages

Lecture

Lecture

58 pages

Lecture

Lecture

49 pages

Lecture

Lecture

36 pages

Lecture

Lecture

11 pages

Lecture

Lecture

12 pages

Lecture

Lecture

58 pages

Lecture

Lecture

33 pages

Exam

Exam

15 pages

Lecture

Lecture

35 pages

Lecture

Lecture

10 pages

Lecture

Lecture

25 pages

Lecture

Lecture

31 pages

Lecture

Lecture

24 pages

Lecture

Lecture

34 pages

Lecture

Lecture

50 pages

lecture

lecture

35 pages

Lecture

Lecture

11 pages

Lecture

Lecture

39 pages

Lecture

Lecture

45 pages

Lecture

Lecture

41 pages

exam1-f05

exam1-f05

11 pages

Lecture

Lecture

4 pages

Lecture

Lecture

17 pages

Exam

Exam

17 pages

malloc()

malloc()

12 pages

Lecture

Lecture

57 pages

Lecture

Lecture

30 pages

Lecture

Lecture

30 pages

Lecture

Lecture

47 pages

Lecture

Lecture

33 pages

Exam

Exam

12 pages

Lecture

Lecture

43 pages

Lectures

Lectures

33 pages

Lecture

Lecture

36 pages

lecture

lecture

33 pages

Exam

Exam

14 pages

Lecture

Lecture

43 pages

Lecture

Lecture

25 pages

Load more
Download Recitation
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Recitation and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Recitation and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?