This is done by putting the process number of the caller into the tp ttypgrp

This is done by putting the process number of the

This preview shows page 40 - 42 out of 140 pages.

becomes the controlling terminal for a process group. This is done by putting the process number of the caller into the tp->tty_pgrp field of the tty_table entry. Following this, the tp->tty_openct variable is incremented and the reply message is sent. A terminal device may be opened more than once, and the next function, do_close (line 14260), has nothing to do except decrement tp->tty_openct. The test on line 14266 foils an attempt to close the device if it happens to be /dev/log. If this operation is the last close, input is canceled by calling tp->tty_icancel. Device-specific routines pointed to by tp->tty_ocancel and tp->tty_close are also called. Then various fields in the tty structure for the device are set back to their default values and the reply message is sent.
Image of page 40
The last message type handler we will consider is do_cancel (line 14281). This is invoked when a signal is received for a process that is blocked trying to read or write. There are three states that must be checked: [Page 341] 1. The process may have been reading when killed. 2. The process may have been writing when killed. 3. The process may have been suspended by tcdrain until its output was complete. A test is made for each case, and the general tp->tty_icancel, or the devicespecific routine pointed to by tp->tty_ocancel, is called as necessary. In the last case the only action required is to reset the flag tp->tty_ioreq, to indicate the ioctl operation is now complete. Finally, the tp->tty_events flag is set and a reply message is sent. Terminal Driver Support Code Now that we have looked at the top-level functions called in the main loop of tty_task, it is time to look at the code that supports them. We will start with handle_events (line 14358). As mentioned earlier, on each pass through the main loop of the terminal driver, the tp->tty_events flag for each terminal device is checked and handle_events is called if it shows that attention is required for a particular terminal. Do_read and do_write also call handle_events. This routine must work fast. It resets the tp->tty_events flag and then calls device-specific routines to read and write, using the pointers to the functions tp- >tty_devread and tp->tty devwrite (lines 14382 to 14385). These functions are called unconditionally, because there is no way to test whether a read or a write caused the raising of the flaga design choice was made here, that checking two flags for each device would be more expensive than making two calls each time a device was active. Also, most of the time a character received from a terminal must be echoed, so both calls will be necessary. As noted in the discussion of the handling of tcsetattr calls by do_ioctl, POSIX may postpone control operations on devices until current output is complete, so immediately after calling the device-specific tty_devwrite function is a good time take care of ioctl operations. This is done on line 14388, where dev_ioctl is called if there is a pending control request.
Image of page 41
Image of page 42

You've reached the end of your free preview.

Want to read all 140 pages?

  • One '20
  • ASCII

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes