Work

Work 20: Asking servers for a fork

posted Dec 21, 2018, 7:17 AM by JonAlf Dyrland-Weaver

Create a forking server system. 
  • start with the persistent server system.
  • add/modify pipe_networking.c/h so that the server side handshake is broken up appropriately.
  • modify the server program to work as a forking server
  • leave the client alone
  • you should submit pipe_networking.c/h as well as both your server and client .c files (and a makefile, as always!)
GitHub link
https://github.com/mks65/forking_server.git

Work 19: Nevertheless, She Persisted

posted Dec 19, 2018, 7:36 AM by JonAlf Dyrland-Weaver

Starting with working handshake code from the previous assignment:
  • COPY your files, do not modify the files in your current handshake repository.
  • Modify there server and client programs:
    • Client
      1. Handshake
      2. Prompt user for input
      3. Send input to server.
      4. Get response from server and display it to user
      5. Repeat steps 2-4 until interrupted (ctrl-c).
    • Server
      1. Handshake
      2. Get data from client
      3. "Process" data - do something interesting to it
      4. Send processed data back to client
      5. Repeat 2-4 until the client exits
        1. When the client exits, the pipes will close automatically
      6. Reset for a new handshake
      7. Include a signal handler for SIGINT that will remove the WKP
GitHub link
https://github.com/mks65/persistent_server.git

Work 18: Lend me a Hand

posted Dec 18, 2018, 8:05 AM by JonAlf Dyrland-Weaver   [ updated Dec 18, 2018, 8:06 AM ]

  • Check out the files on https://github.com/mks65/networking
    • Copy them all.
  • Fill in the function definitions for server_handshake and client_handshake in pipe_networking.c.
    • These should do everything needed to establish a 3-way handshake between the client and server.
    • make sure you include diagnostic print messages in your functions.
  • make and test
  • You should not modify any other files for this assignment.
Github clone link:
https://github.com/mks65/handshake.git

Work 17: Semaphone

posted Dec 12, 2018, 6:56 AM by JonAlf Dyrland-Weaver

This will be due Friday, 12/14

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

Work 16: Sharing is caring.

posted Dec 4, 2018, 6:39 AM by JonAlf Dyrland-Weaver

Shared memory is a thing, and it's exactly what it sounds like. You can learn more about it here:


Once you've learned a thing or two, write a program that does the following:
  1. Connects or creates a shared memory segment large enough to hold a 200 character string.
  2. Displays the contents of the shared memory.
    • If the segment was just created, instead show a message saying as much.
  3. Ask the user if they want to change the data in the segment.
    • If yes, prompt the user to enter a new string and write that to the segment.
  4. Ask the user if they want to delete the segment, if yes, then delete it.
Github submission link
https://github.com/mks65/shmegegge.git

Work 15: Please fork responsibly.

posted Nov 16, 2018, 7:48 AM by JonAlf Dyrland-Weaver

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

Work 14: Get Argumentative

posted Nov 14, 2018, 5:50 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] = "woah-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 no more than 5 arguments
    • The original string is correctly formatted

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

Work 13: Fire up the bat signal!

posted Nov 8, 2018, 6:01 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
https://github.com/mks65/signals.git

Work 12: Please follow the dir(rections)

posted Nov 1, 2018, 7:04 AM by JonAlf Dyrland-Weaver   [ updated Nov 2, 2018, 5:45 AM ]

New and improved instructions:
  • Your program should handle user input as follows:
    • If a command line argument is entered, use that as the directory to scan.
    • If not, the program should ask the user to enter a directory to scan.
    • In either case, don't assume your user knows what they are doing, if an invalid directory is entered, take reasonable action (*ahem* errno *cough cough*)

With your *new* table buddy, 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 link:
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 11: I need information, STAT!

posted Oct 30, 2018, 5:32 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
  • Note
    • You may hardcode the file that your program uses, make sure the program works when I download and run it.
    • If only there were some file that you know I will have and where it is... hmm...
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:
https://github.com/mks65/stat.git

1-10 of 21