Signals and Interprocess Communication

  • SIGTERM: A Unix signal providing a mechanism for notifying of system events.
    • Two different types of SIGTERMs
      1. Asynchronous: Generated by events outside the control of the process that receives them, and arrive at unpredictable times such as user input Ctrl+C
      2. Synchronous: Generated by exceptions, or errors, which are caused by invalid operations in a program such as dividing by zero.
  • POSIX standard specifies 20 signals 2 of which are user definable

 

Reciveing Sigterms

  • When receiving a asynchronous SIGTERM the processor can 1. ignore or 2. executed specified procedure
    • If unspecified there are 5 default procedures which may happen
      1. Terminate process
      2. Write execution context and contents of the address space to a file (called core dump) and terminate
      3. Ignore
      4. Suspend process
      5. Resume the process’s execution if it was previously stopped

 

IPC Resources: Semaphores, message queues, and shared memory

  • Kernel implements these as IPC resources and a process can declare these data structures with function calls which
    • Return System V data structure identifiers specific to the function eg. semget() returns a semaphore set identifier
      shmget(), semget(), msgget()
  • These data structures stick around like file descriptors and must be deallocated.  For example semaphores will be deallocated with
    sem_destroy()

    which returns 0 on success and -1 otherwise.

  • Message Queue: Allow processes to exchange messages with the following functions
    msgsnd() and msgrcv()
    • Note POSIX has its own standard which is simpler file based interface vs Sys V
  • Shared Memory:  Allocated memory from
    shmget()

    which returns a memory segment identifier if suceess.

    • For any process to access shared memory it must invoke
      shmat()

      which attaches the System V shared memory segment identified by shmid to the address space of the calling process.  And once finished detaches by using

      shmdt()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s