All assignments are to be submitted as submodules in the correct period directory for the assignment. Please see the resources page for help on linking your own repository as a submodule.

Last Class Today!

At the end of each class, 1 student will be chosen at random to 
post the day's notes online.
Notes will be posted in a document titled lct-[PERIOD].md in the dwsource 
repository on github (
Title the note [DAY] [DATE] [TOPIC/AIM] by [AUTHOR]
For example:   Wednesday, 9/14 Variable Types by JonAlf Dyrland-Weaver
Also include at the end of the note a link to an interesting 
piece of tech/science news.
Use markdown for formatting. For markdown help go here:

Work 17: Fork over the data now!

posted Dec 19, 2017, 6:59 AM by JonAlf Dyrland-Weaver

Create a working forking server program, as described in class yesterday.
  • Check out the files in the src/ directory on
    • COPY them, do not move them!
  • Fill in the function definitions for server_setup and server_connect in pipe_networking.c.
  • Fill in the body of forking_server.c to implement a forking server program.
    • Use server_setup and server_connect, not server_handshake
    • Include a separate function for the subserver
    • Write your own process function
    • Make and test!

Work 16: Lend me a hand

posted Dec 12, 2017, 7:47 AM by JonAlf Dyrland-Weaver   [ updated Dec 12, 2017, 12:20 PM ]

  • Check out the files in the src/ directory on
    • COPY them, do not move them!
  • Fill in the function definitions for server_handshake and client_handshake in pipe_networking.c.
  • make and test
  • You do not need to modify any other files for this assignment.

Work 15: Semaphone!

posted Dec 8, 2017, 6:19 AM by JonAlf Dyrland-Weaver   [ updated Dec 8, 2017, 7:48 AM ]

With your table buddy, write a telephone style game! It will use a semaphore to control access to a file and shared memory. 

The main program should work as follows:
  1. Print a message this it will check if resources are available.
  2. When they are, display the last line added to the story (or none, if it is new).
  3. Prompt the user to enter the next line
  4. Update the story
  5. quit

This game will require 2 files 
  1. A control program
    • Take a command line argument to determine if it is creating or removing the resources or viewing the story.
    • If creating (command line argument: -c):
      • Should make the shared memory, semaphore and file (open the file with the truncate flag). 
      • Set any values that are needed.
    • If removing (command line argument: -r)
      • Remove the shared memory, the semaphore and the story.
      • Display the full contents of the story.
      • This should wait until the semaphore is available.
    • If viewing (command line argument: -v)
      • Output the contents of the story file. 
      • This mode does not need to interact with the semaphore
  2. A main writing program
    • Will attempt to access the resources using the semaphore
      1. Once in, it should display the last line added to the file (use shared memory to contain the size of the last line).
      2. Prompt the use for the next line.
      3. Once a new line is read, write that to the file, update the shared memory and then release the semaphore
  3. You do not need a run target in your makefile
github links:

Work 14: Get sem control!

posted Dec 6, 2017, 6:10 AM by JonAlf Dyrland-Weaver   [ updated Dec 6, 2017, 6:20 AM ]

Write a program that can be used to control a semaphore. It should be able to handle the following command line arguments:
  • -c N
    • Create a semaphore and set its value to N
    • If the semaphore already exists, it should pint a message saying so
  • -v
    • View the current value of the semaphore
  • -r
    • remove the semaphore
Note: you can use $ ipcs -s to check on any active semaphores from the command line. This will be useful to develop your program.

Sample program output:
Example output:
$ ./control -c 4
semaphore created: 589842
value set: 0
$ ./control -v
semaphore value: 4
$ ./control -c 3
semaphore already exists
$ ./control -v
semaphore value: 4
$ ./control -r
semaphore removed: 0

In order to create this function, you will need to be able to set and view the semaphore, that has to be done using the semctl function
    • DESCRIPTOR: return value of semget
    • INDEX: Index of the semaphore in the semaphore set
    • OPERATION: For this assignment, you only need the following operations:
      • SETVAL
      • GETVAL
    • DATA: Required for SETVAL
    • Check out $ man semctl for more info. Focus on SETVAL and GETVAL
Github clone link:

Work 13: Check your pipes for leaks.

posted Nov 20, 2017, 7:19 AM by JonAlf Dyrland-Weaver

Write a program that does the following:
  • Creates 2 unnamed pipes
  • Forks off a child process
  • Sends a number from the parent to the child
  • The child should perform some arithmetic operation on that number, then send the new value to the parent
    • Do whatever math your heart desires
  • Display messages for each step of the process
Example output:
[parent] sending: 15
[child] doing maths on: 15
[parent] received: 225

github link

Work 12: Please Fork Responsibly

posted Nov 16, 2017, 7:15 AM by JonAlf Dyrland-Weaver

With your table buddy, write a c program that does the following:
  • Forks off 2 child processes
  • Child process instructions:
    • At the start print its pid
    • Sleep for a random number of seconds in the range [5, 20]
      • Each child should sleep for a (potentially) different amount of seconds
    • At the end print a message that it is finished
  • Parent process instructions
    • Before forking, print out some initial message
    • After the fork, wait for any child to finish
    • Once a child has finished, print out the pid of the completed child as well as how many seconds it was asleep for.
      • Do not run any kind of timer, think about how the child could send this information back to the parent.
    • Print a message that the parent is done and then end the program
      • The other child might still be running, that's ok.
github clone link

Work 11: Don't get argumentative

posted Nov 10, 2017, 6:11 AM by JonAlf Dyrland-Weaver

With your table buddy, do the following:

strep is a function in string.h used to help parse strings
  • strsep( <SOURCE>, <DELIMETER> )
  • Locates the first occurrence of any character in the DELIMITER string and replaces it with NULL
  • Returns the beginning of the original string
  • sets the source string pointer  to point to the index 1 byte after the location of the new NULL
  • Since the source variable's value is changed, it must be a pointer to a string.
  • To test it out, try the following code:
  • char line[100] = "wow-this-is-cool";
    char *s1 = line;
    printf("[%s]\n", strsep( &s1, "-" ));
    printf("[%s]\n", s1);

Write a function that uses strep to parse a line of arguments
  • Use the following header: char ** parse_args( char * line );
  • It should take a string with the command line invocation of a program (like "ls -a -l")
    • Note that there is a " " between each argument
  • Return an array of pointers to each individual argument in the parameter string, that could be used for execvp()
  • For example, the following code should work (assuming all variables are declared appropriately:
    • char ** args = parse_args( line );
      execvp(args[0], args);
  • You can make the following assumptions:
    • There is only 1 space between each argument in the original string
    • The original string contains mo more than 5 arguments
    • The original string is correctly formatted

github link:

Work 10: Fire up the batSIGNAL

posted Nov 8, 2017, 6:36 AM by JonAlf Dyrland-Weaver

Write a C program with the following features:
  • Runs constantly inside a forever while loop.
  • Print out the process' PID inside the loop.
  • Use the sleep(1) function to have the program wait 1 second between inner loop iterations.
  • Catch the following signals
    • SIGINT
      • Before exiting, append a message to a file noting that the program exited due to SIGINT
      • To make your program quit, look up the exit function.
    • SIGUSR1
      • Print out the PID of the parent process.
      • Should not cause the program to exit.
github link

Work 09: Please follow the DIRections

posted Nov 1, 2017, 8:44 PM by JonAlf Dyrland-Weaver

You will write a program that will gather various information about a directory, specifically:
  • list all the files in the directory
  • specify which files are directories (if any)
  • show the total size of all the regular files the directory
    • note that you do not have to recursively go through any subdirectories to find their size for this part (unless you want to, but that is not a simple task)
  • Have the program scan the current directory
  • Possible enhancements:
    • Recursively list the files in any subdirectories, update the total to include the total size of subdirectories
    • Print out the size in a more readable format (like using KB, MB, GB for -byte prefixes)

Github links:

Below is sample output, yours may differ, but as long as it presents the information requested above you will receive full credit.
$ ./a.out
Statistics for directory: .
Total Diectory Size: 13453 Bytes
Regular files:

$ ./a.out
Statistics for directory: .
Total Diectory Size: 17766 Bytes
Regular files:

Work 08: I need information, STAT!

posted Oct 31, 2017, 7:13 AM by JonAlf Dyrland-Weaver

There is a function called stat. It is used to get information about a file. With your table buddy, write a program that uses stat to display the following information about a file:
  • file size
  • mode (permissions)
  • time of last access (displayed in the following format: Fri Oct 28 09:03:01 2016
Once you have that, try the following:
  • Modify the size so it is printed out in human readable form (that is using B, KB, MB, GB).
    • You may want to look into the sprintf function to help.
  • Attempt to print out the permissions in ls -l form, ignoring the early bits that include the file type information
    • Permissions are of type mode_t, which is an integer type.
    • The permissions section of the mode is stored in the last 9 bits of the mode_t data type.

Github clone url:

1-10 of 18