Work

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 (https://github.com/mks65/dwsource.git).
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: https://daringfireball.net/projects/markdown/basics

Work 9: If there's a leak, check the pipes!

posted Dec 15, 2016, 7:13 AM by JonAlf Dyrland-Weaver   [ updated Dec 16, 2016, 7:26 AM ]

In pairs (not table buddies, assigned in class) do the following:
  • check out the pipe files in the dwsource github repository: https://github.com/mks65/dwsource
  • create the files pipe_networking.h and pipe_networking.c that will contain the handshake procedures required in server.c and client.c
  • create a makefile that will compile everything
To be continued... right now!
  • grab the fserver.c file from the source code page. 
  • add the server handshake functions to your pipe_networking.c file that will facilitate a forking server.
  • write the functions so they will fir the arguments used in fserver.c
github link:
https://github.com/mks65/pipes.git

Work 8: Ring ring ring ring... semaphone!

posted Dec 8, 2016, 7:02 AM by JonAlf Dyrland-Weaver   [ updated Dec 15, 2016, 6:59 AM ]

With your table buddy, write a telephone style game simulator! It will use a semaphore to control access to a file and shared memory. This will be due on Monday.
You will need 2 programs:
  1. Control for the resources
    • Should 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 and the semaphore
      • Display the full contents of the story.
    • If viewing (command line argument: -v)
      • Output the contents of the story file. 
      • This mode does not need to interact with the semaphore
  2. The writing program
    • Will attempt to access the resources using the semaphore
      • Once in, it should display the last line added to the file (the shared memory should contain the size of the last line).
      • Then prompt the use for the next line.
      • Once a new line is added, it should 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:
https://github.com/mks65/semaphone.git

Work 7: The Executor Arrives

posted Nov 18, 2016, 6:40 AM by JonAlf Dyrland-Weaver


With your table buddy, write a c program that runs a command line program that may have arguments. It should work as follows:
  • Prompts the user for a program to run via the command line.
  • Reads in that line (using fgets) and parses it to be used by one of the exec functions.
  • Runs the command using exec
  • You do not need to fork off a separate process and wait, the purpose of this assignment is only to parse a single line of input and run a program once.
Example output:
$ ./a.out 
What would you like to do? ls -l
total 72
-rwxr-xr-x  1 dw  staff  8904 Nov  9 23:18 a.out
-rw-r--r--  1 dw  staff   520 Nov  9 23:33 executor.c
-rw-r--r--  1 dw  staff   294 Nov  9 23:10 executor.c~
-rw-r--r--  1 dw  staff   294 Nov  7 14:03 launcher.c
-rw-r--r--  1 dw  staff   301 Nov  7 11:16 launcher.c~
-rw-r--r--  1 dw  staff   740 Nov  7 13:41 procfun.c
-rw-r--r--  1 dw  staff   734 Nov  7 10:41 procfun.c~
$

github link:
https://github.com/mks65/executor.git

(The executor was Darth Vader's flagship, for more information on the title itself see here)

Work 6: Fire up the batSIGNAL

posted Nov 9, 2016, 10:53 AM by JonAlf Dyrland-Weaver

WITH YOUR TABLE BUDDY

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
https://github.com/mks65/signals.git

Work 5: Please Follow the DIRections

posted Nov 2, 2016, 6:17 AM 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:
https://github.com/mks65/dirinfo.git

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
Directories:
        .
        ..
Regular files:
        a.out
        dirinfo.c
        dirinfo.c~
        dirstuff.c
        dirstuff.c~

$ ./a.out
Statistics for directory: .
Total Diectory Size: 17766 Bytes
Directories:
        .
        ..
        dir
        structRW
Regular files:
        a.out
        error.log
        filelist
        files.c
        read.c
        ReadTest
        redirect.c
        redirect.c~
        redirect_full.c
        redirect_full.c~
        redirTest
        statfiles.c
        statfiles.c~
        write.c
        WriteTest


Work 4: I need information, Stat!

posted Oct 28, 2016, 6:13 AM by JonAlf Dyrland-Weaver   [ updated Oct 30, 2016, 4:42 PM ]

There is a function called stat. It is used to get information about a file. With your table partner, 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
Added 10/31. In the same file:
  • Modify the size so it is printed out in human readable form (that is using B, KB, MB, GB).
  • Attempt to print out the permissions in ls -l form, ignoring the early bits that include the file type information (the permissions section of the mode is stored in the last 9 bits of the data type).

Github clone url:
https://github.com/mks65/stat.git

Work 3: DEVise a random plan

posted Oct 25, 2016, 2:27 PM by JonAlf Dyrland-Weaver   [ updated Oct 25, 2016, 2:30 PM ]

With a buddy, write a c program with the following features:
  • A function that generates a random int by reading in 4 bytes from /dev/random.
  • A main function that
    1. populates an array with 10 random numbers generated by your random function (print out each value)
    2. writes the array to a file
    3. reads that file into a different array
    4. prints out the contents of the second array to verify the random numbers are the same from step 1
  • Remember to use good practices, like checking return values for errors
  • Also remember to include a makefile that includes a run target (even though this is a single file program)
  • You should be able to read from the array without using a loop.
  • Make sure both team members' names are in the github directory name.

github clone links
https://github.com/mks65/randfile.git
 
Sample output:
Generating random numbers:
        random 0: 198116400
        random 1: 2592608753
        random 2: 2833624368
        random 3: 3273750590
        random 4: 3548697368
        random 5: 3876828898
        random 6: 2617393183
        random 7: 1720936907
        random 8: 682596330
        random 9: 2411695830

Writing numbers to file...

Reading numbers from file...

Verification that written values were the same:
        random 0: 198116400
        random 1: 2592608753
        random 2: 2833624368
        random 3: 3273750590
        random 4: 3548697368
        random 5: 3876828898
        random 6: 2617393183
        random 7: 1720936907
        random 8: 682596330
        random 9: 2411695830

Work 2: enlist your coding skills

posted Oct 7, 2016, 7:12 AM by JonAlf Dyrland-Weaver

Write a simple linked list program. You will need a define a node struct with the following data members:
  • A piece of data (your choice, but make it a primitive data type)
  • A pointer to the next node
  • Put the struct declaration at the top of your code (after the include lines), or in a separate .h file
  • Here's an example of what the struct could look like:
      • struct node { int i; struct node *next };
Create the following functions:
  • print_list
    • Should take a pointer to a node struct and print out all of the data in the list
  • insert_front
    • Should take a pointer to the existing list and the data to be added, create a new node, put it at the beginning of the list and return a pointer to the beginning of the list.
  • free_list
    • Should take a pointer to a list as a parameter and then go through the entire list freeing each node and return a pointer to the beginning of the list (which should be NULL by then).                
Don't forget to test out these various functions to ensure they work correctly. (Just to be clear, when you run the program and get "Segmentation fault" that means it's not working.)

Github link:
https://github.com/mks65/list.git

Work 1: If you liked it then you should've put a string on it.

posted Sep 27, 2016, 5:57 AM by JonAlf Dyrland-Weaver   [ updated Sep 29, 2016, 8:35 AM ]

This will be due Wednesday 10/5 at 8am

First, acquaint yourself with the basic string functions: strlen, strcpy, strcat, strncat and strncpy. You can look at the man pages for each if you are unclear as to their uses. I encourage you to play around with each so you are comfortable with how to use them. Then write your own versions of the following:
  • Required
    • strlen [ int strlen( char * ) ]
    • strcpy/strncpy (choose one)  [ char * strcpy( char *dest, char *source )  char * strncpy( char *dest, char *source, int n)  ]
    • strcat/strncat (choose one)  [ char * strcat( char *dest, char *source )  char * strncat( char *dest, char *source, int n)  ]
    • strcmp  [ int strcmp( char *s1, char *s2 ) ]
    • strchr  [ char * strchr( char *s, char c ) ]
    • You must test every function you write, you will not get full credit for an untested functions
    • You do not need to write 7 functions, only 5, but you need to write 1 or the "n" versions. 
      • (So if you do strcpy then you have to do strncat)
    • A makefile that includes a run target. Do not automatically call run in the first target.
  • Extra
    • strstr
    • The other strn/str version of the functions you wrote above
  • When you test your functions, you might want to run them alongside the regular ones so you can see if they behave exactly the same way or not.
  • Remember you should call them something other than the regular names (like, mystrlen...). 
Github link
https://github.com/mks65/stringy.git

Here's an example of what your code might look like when run:
Before applying functions:
s1 = Hello, length = 5
s2 = , length = 0

Testing regular functions:
Copy s1 to s2: s2 = Hello, length = 5
Cat "Man" to s2: s2 = HelloMan, length = 8
s1 = Hello, length = 5

Testing "n" functions:
s2 = this is l, length = 9
s2 = Hello, length = 5
s2 = Hello123, length = 8

Testing strcmp:
compare ab to abc: -99
compare abc to ab: 99
compare abc to abc: 0

Testing strchr: 
Looking for 1 in Hello123: [1] 
Looking for 0 in Hello123: []

Testing strstr: 
Looking for cde in abcdefg: [cdefg] 
Looking for abe in abcdefg: [(null)]

Work 0: Eul up your skills!

posted Sep 16, 2016, 7:32 AM by JonAlf Dyrland-Weaver

The time has come for you to actually write a c program.
  1. Look at the problems here: http://projecteuler.net/index.php?section=problems
  2. They are all math problems of some sort, pick two and write a c program to solve it.
    • Finished early? pick a third, a fourth, a fifth...
  3. Remember, c syntax is the same as java, so all your old friends (if, while, else, for...) are around.
  4. Use scanf if you need user input (we'll talk about it tomorrow, but you can do man scanf to get info on it)
Github link
https://github.com/mks65/euler.git

1-10 of 10