______ In-class notes for 08/31/2020 (CS 273 (OS), Fall 2020)
Home
>>     < >




In-class notes for 08/31/2020

CS 273 (OS), Fall 2020

  • Homework assignment

    • HW policies:

      • Full credit if complete and on time

      • Full credit if part-complete on time, and you make up the rest within a week

    • Questions?

  • Shell project assignment

  • Reading assignment: Read Sections 2.1-2.2 on processes and threads.

Selected Linux system calls

  • Some numerical identifiers in Linux:

    • File descriptors (used in open(), read(), write(), dup(), pipe(), close(), etc.) -- identifiers for local files.

      Other operating systems may refer to such identifiers as handles. File descriptors are small integers (seldom the case for handles).

    • getpid() returns process id (PID) -- every process has a unique integer identifier.

         % ps auxww | more
      

    • getppid() returns parent's process id -- if process P calls getppid(), the return value is the PID of the process that called fork() to create P.

    • getpgrp() returns id of the process group containing this process. Each process belongs to a process group, and Linux signals (such as the signal caused by CTRL/C) are sent to all processes in a group.

    • getuid() returns the file-system user id (UID) for the calling process (i.e., the process that calls getuid()).

      • Each process has a UID associated with it that is automatically assigned to any files that process creates.

      • Process's current UID also determines what privileges that process has for files and directories, such as read access, write access, executable access.

    • getgid() returns file-system group id (GID) for the calling process, also automatically assigned as the group for any files created by that process.

      • Files and directories can also assign access to group ids.

      • UID and GID are defined in the password file /etc/passwd .

      • UIDs can belong to other groups beside their default GID, as defined in the file /etc/group. File-system system calls can generally check privileges for all the groups a UID may belong to.

    • geteuid() and getegid return the effective UID and effective GID for the process. Linux makes it possible for a process P temporarily to take on a different UID and GID, called the effective UID and GID. That process P's original UID and GID are called its real UID and GID, and the real UID/GID combination can be retrieved using getuid() and getgid().

    • setuid(), setgid(), seteuid(), and setegid() system calls enable a process to set its effective UID and GID. Exception: for a root process (superuser), setuid() and setgid() also change the real UID and GID, respectively, thus relinquishing its superuser privileges permanently.

  • Signals provide an operating-system mechanism for processes to communicate with each other, or for the kernel to communicate with a (user-level) process. For example, entering CTRL/C at a terminal causes the Linux terminal driver to deliver a signal (called SIGINT) to the process currently reading standard input. Likewise, Linux provides timer mechanisms that delivers SIGALRM signals when a designated time period has elapsed. Processes may respond to a signal by providing a signal handler function before that signal is sent. A process is destroyed if it receives a signal type for which it has not designated a signal handler.

    One process can send a signal to another process using the kill() system call. The signal() system call assigns a handler function for a particular type of signal (e.g., SIGINT). System calls alarm(), pause(), and setitimer() are used to manage timers.

  • Demo: ~cs273/egs/signal.sh

    Man page signal(2), /usr/include/signal.h, /usr/include/bits/signum.h...

  • BSD networking: Socket descriptors (treated as file descriptors)




< >