CSCI 4061
Fall 2017

Class Information
Lecture Schedule and Notes
Recitation Schedule and Notes
Assignments and Exams
Class Forum (Moodle)
Assignment Submission (Moodle)
Grades (Moodle)
Online Quiz Exercises
Examples
Useful Resources
CSCI 4061
Introduction to Operating Systems

CSCI 4061   -   Spring 2013

Examples



Shell Scripts
  • hello (tcsh) - hello (bash) -  A simple Hello World shell script.
  • name (tcsh)  -  name (tcsh) - Shell script using variables.
  • arg_demo (tcsh)  -  arg_demo (bash)  -Shell script involving command line arguments.
  • shift_demo (tcsh) - shift_demo (bash) - Shell script using shift with command line arguments.
  • keyin_demo (tcsh) - keyin_demo (bash) -Shell script reading user data input from standard input.
  • quotes_demo (tcsh) - quotes_demo (bash) - Shell script demonstrating use of quotes.
  • forEach (tcsh) -  forEach (bash) -   example of iteration using foreach construct
  • files_demo (tcsh) - files_demo (bash) -  Shell script dealing with files and using if-then-else.
  • file-list-iterator  this example shows how to assign output of a system command to a shell variable
  • filesize  (tcsh) -  filesize (bash)  - compute the sum of all files in a directory (non-recursive)
  • numeric_demo - Shell script demonstrating numeric data processing.
  • menu (tcsh) - menu (bash) -Demonstrating printf
  • menu2, menu.txt - Demonstrating cat in a script ( and supporting textfile)
  • here - Demonstrating the "here document"
  • switch_demo (tcsh) - switch_demo (bash) -Demonstrating the use of switch
  • switch-demo-2   Demostrating pattern matching in selecting cases in a switch statement
  • usage - Checking & using arguments
  • pattern2 - Avoiding quoting pitfalls
  • main, subroutine - Using another script as a subroutine
  • recursive, dorecursive - requires setting of environment variable, dorecursivepath requires setting of the path - Recursive usage of scripts
File I/O Examples
  • Echo It reads lines from stdin and writes to stdout.
  • File copy It creates a copy of an existing file.
  • File append It appends a file at the end of another file.
  • seekout - an example of lseek An example of lseek, creates null bytes by seeeking beyond the end of the file.
  • myls0.c myls1.c myls2.c myls3.c myls4.c myls5.c mylsFinal.c Example of opendir and readdir to list a directory's content. stat call, ctime, getpwuid, getgrgid
  • statdemo.c Getting sum of all files in a directory using stat.
  • lstatdemo.c Prints file type (dir, reg, lnk) for each file in a directory
  • dupdemo.c Using dup to redirect output from a file to standard output.
  • makdir.c Make a new directory
  • rmvdir.c Remove a directory
  • rmvfile.c Remove a file
  • changedir.c  Change the current working directory of the process executing this code
  • pwdir.c   getcwd.c Print current working directory
  • myfind.c  A simple version of "find" program to find in a specified directory all files whose names contain a given string. NOTE: No wildcards accepted.
  • If you execute as "myfind   dirname  hel"
  • It will find files with names such as hello.c, help.txt, shell.txt,  if present in the directory tree specified by "dirname". Their names contain string "hel".
  • linkinfo.c  This program reads all entries in a given directory, and for each  symbolic link in the directory, it prints the link information, i.e. the path information contained in the link.  This program makes use of the system call function readlink().
  • makelink.c  This program creates a new symbolic link (path name) for an existing file. It uses system call function symlink(). This program is similar to "ln -s" for creating a symbolic link.
  • fmtout.c Examples for formatted output
  • fmtinput.c Examples for formatted input. citylist Examples of input for the formatted input example program.
  • timeinfo.c  This example shows how to use strftime(0 function to generate current date time in a desired format such as MONTH-DD-YYYY-HH-MM-SS, e.g.  Feb-13-2013-16-59-08
Process Management
  • Description of various examples in this section
  • printpid.c Print process id, parent process id, user id.
  • process-chain.c Example of repeated fork calls to create a chain of parent-child. Example 2.5 from the book.
  • process-fan.c Example 2.6 from the book.
  • process-tree.c Example 2.7 from the book.
  • Example 1 Example of fork-exec using execl.
  • Example 2 Example of fork-exec using execv.
  • Example 3 Example of fork-exec in which the child executes a shell command
  • Example 4 Example of fork-exec -  parent waits for child finish and return its PID as status
  • Example 5 Parent opens the file with name "input", 
  •                     creates a child, across the fork child and parent will share the file descriptor
  •                     both child and parent read from the same descriptor and the output  gets interleaved by the outputs of the two
  • Example 6  Parent creates the child  and uses the WNOHANG option of waitpid. Parent is not blocked in wait.
  • Pipeline Example of creating a pipe between two processes.
  • Exit status of a child process Example of how a process obtains exit status of its child.
Examples of POSIX Thread Programming
  • POSIX Thread Programming Examples
Concurrent Programming
  • Serilized writing to stderr by concurrent children This example illustrates the output produced when child processes in a process chain write to stderr in a serial order.
  • Interleaved writing to stderr by concurrent children when the writes are not synchronized. This example illustrates the output produced when child processes in a process chain write concurrently to stderr in a unsychronized manner.
  • Examples of concurrent programming using POSIX seamphores, shared memory, System V semaphores
Examples of SYSTEM V Semaphores
  • System V sempahore Examples
Signal Management
  • Example programs for signal handling
  • More example programs for signal handling
String Manipulation
  • pathparse.c Parsing a path into filename & base
  • str_demo.c Another string manipulation demo
  • strtok_ex.c Parsing strings into tokens using strtok
  • get_strings.c Using fgets to retrieve strings from a file
Dynamic Memory
  • Shared Memory
  • dynamic1.c A demo of malloc and free
  • dynamic2.c A demo of calloc and realloc
TCP/IP Example Programs
  • TCP, UDP, sockets and select() Examples from recitation
TCP/IP Example Programs
  • TCP and UDP examples