Konstantinovich

Email: 
    konstans@stuy.edu

Office Hours:
    Periods 6,7,8  in room 301
    Note: 6th is my lunch and I tend to be out getting food the 1st 10 minutes of the period


2018-11-16 Fork Responsibly

posted by Konstantinovich Samuel

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 repo:
MKS65C-forkin

2018-11-14 Handling Arguments like a boss

posted Nov 14, 2018, 10:49 AM by Konstantinovich Samuel   [ updated Nov 14, 2018, 12:08 PM ]


With your table buddy, do the following in the repo "MKS65C-parseargs"


strsep is a function in string.h used to help parse strings
  • strsep( <SOURCE>, <DELIMITER> )
  • 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 strsep 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

2018-11-09 Signals

posted Nov 9, 2018, 10:10 AM by Konstantinovich Samuel

Goal: Sending Mixed Signals

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 repo:
MKS65C-signals

2018-11-06

posted Nov 6, 2018, 6:02 AM by Konstantinovich Samuel

Minutes from yesterday:
Yoshiya is the winner!

Everyone That Did Minutes -> Verify + fix your header levels to match the others

I see your minutes:
Raymond Wu
Raunak Chowdhry
Alexander Liu
Jabir Chowdhury
Karen Li
Cooper Nissenbaum
Hasif Ahmed
Kevin Ly
Nadine Jackson
Maggie Zhao
Calvin Aw
Andy Zhou

Did not yet do minutes:
Imad
Camilla
Joan
Horace
Adil
Ahnaf
Puneet
Brian
Aaron
Jason
Jack
Mandy
Matthew
Bill
Tina
HuiMin
Michael
WeiWen

2018-11-01 Dir

posted Nov 1, 2018, 12:18 PM by Konstantinovich Samuel   [ updated Nov 5, 2018, 12:21 PM ]

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)
    • Print out other file info (permissions owner group etc)

Everyone needs aGithub Repo:
MKS65C-dirinfo
-Include your partner name  Last.First.txt  
-One partner include the lab.


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

2018-10-30 stat (not cat) your files!

posted Oct 30, 2018, 11:44 AM by Konstantinovich Samuel   [ updated Oct 30, 2018, 12:18 PM ]

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 repo:
MKS65C-stat

2018-10-28 pseudo random in, psudo random out

posted Oct 29, 2018, 12:08 PM by Konstantinovich Samuel

Write a c program with the following features:
  • A function that generates a random number by reading in the correct number of 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
      • Do not use a loop when writing to the file
    3. reads that file into a different array
      • Do not use a loop when reading from the file
    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 separate run target 
github repo:
MKS65C-randomfile

 
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

2018-10-23 File a complaint

posted Oct 23, 2018, 11:03 AM by Konstantinovich Samuel

Remember permissions in linux are a 3 digit octal number. 
777 is: 111 111 111(binary)
532 is  101 011 010(binary)
  • Look at your computer number and mod it by 2.
  • Based on that number, look up and figure out what the following functions do
    • 0: open / close
    • 1: read / write
  • After 5 minutes or so, once you have a grasp on your functions, the parameters, return values and whatnot, talk to your table buddy and discuss the functions.
  • Once you and your table buddy have it all figured out, write a program that tests all 4 functions.
  • One submission per duo.
MKS65C-file  (copy/paste please)
Remember: 
-One repo has the code.
-Both partners need a file with their partner's name.
    e.g.
    dole.bob
    yamaguchi.giacomo
-If you have no repo, you will lose points!



2018-10-18 - Sieve of Eratosthenes

posted Oct 18, 2018, 12:13 PM by Konstantinovich Samuel   [ updated Oct 19, 2018, 11:57 AM ]

You must use the sieve of Eratosthenes, not some other algorithm. 

You are eliminating the multiples of each prime, then finding the next non-eliminated number which must be prime, and repeating.
Eliminate multiples of  2 (but not 2),
3 is next, eliminate multiples of 3,
then the multiples of 5 etc.

Whatever has not been eliminated (white in the picture) is prime. Note that you just need a prime/not-prime state, don't worry what divides the number.


Kontest Requirements:

Submit by Thursday October 25th Morning
Submit a link to your repo here: (ONLY if you want to enter the competition)
https://goo.gl/forms/ca7lkn1cq62JKLA63


1. You must make a repo and place sieve.h and sieve.c inside that directory, not a subdirectory:

2. Your sieve.h should have the function:
    
  int sieve(int targetPrime);

3. There should be no printed output when sieve() is called!

I will use a driver of mine.
I will compile with the -lm flag so you can use math.h.


K-specific requirements:


 name your repo:
        
MKS65C-sieve
  




Optionally:
In your makefile, you can pass args to the program:

run:
    ./primetest $(args)


Then you can use the shell as follows:
 
make run args="100000 10"


Feel free to use this driver file in your testing:


#include <stdio.h>
#include <stdlib.h>
#include "sieve.h" int main(int argc, char * argv[]){ int iterations = 1; int target = 1000000; if(argc > 1){ target = atoi(argv[1]); } if(argc > 2){ iterations = atoi(argv[2]); } int ans = 0; while(iterations>0){ ans=sieve(target); iterations--; printf("The n=%d prime is %d\n", target, ans );
//this is to modify which prime to //potentially avoid CPU caching target++; } return 0; }

2018-10-12 Project0 - SickMusicPlayer

posted Oct 12, 2018, 10:40 AM by Konstantinovich Samuel   [ updated Oct 12, 2018, 10:44 AM ]


PROJECT: sickMusicPlayer aka lowFunctionalityMusicPlayer

DUE: Wed Oct 17th
You may work with up to 1 other person, and that is highly encouraged.

Write a program in C that implements a music library organizer. The data structure should consist of an array of 27 slots (one for each letter from 'a' to 'z', and another for other symbols). Each slot will contain a linked list of all the artists that have names that start with the corresponding letter. When you add a song, it should go on to a linked list at the appropriate array slot in the correct position alphabetically. Assume no duplicate songs.

Your nodes/links should be able to hold a song's title and artist. You might use structures like the following:
struct song_node{ 
  char name[100];
  char artist[100];
  struct song_node *next;
};


//and later:

struct song_node * table[27];

You should start by making your linked lists work with the following functionality:
  • insert nodes at the front
  • insert nodes in order
    • alphabetical by Artist then by Song
  • print the entire list
  • find and return a pointer to a node based on artist and song name
  • find and return a pointer to the first song of an artist based on artist name
  • Return a pointer to random element in the list.
  • remove a single specified node from the list
  • free the entire list
Then create your array of linked lists for the full program to have the following functions:
  • Add song nodes.
  • Search for a song given song and artist name (return a pointer).
  • Search for an artist.
  • Print out all the entries under a certain letter.
  • Print out all the songs of a certain artist
  • Print out the entire library.
  • Shuffle - print out a series of randomly chosen songs.
  • Delete a song
  • Clear the library.
Files you should have:
  • A .c file that contains the main function you use to test all your work
  • Two sets of .h/.c files
    • There are 2 separate structures being worked on, the linked list and the library.
  • A makefile that will compile all the parts of your code and generate a single executable program
Git repo:
MKS65C-Tunes
-One repo per group should have code.
-All repos should have the name of their partners as a text file.
    e.g.
    Kim.Leeroy
    Smith.Jinkyu

You must test all the functions in your main function in order to receive full credit!!!

Example of reasonable testing output:
LINKED LIST TESTS
====================================

Testing print_list:
ac/dc: thunderstruck | pearl jam: alive | pearl jam: even flow | pearl jam: yellow ledbetter | pink floyd: time | radiohead: paranoid android | radiohead: street spirit (fade out) | 
====================================

Testing print_node:
ac/dc: thunderstruck
====================================

Testing find_node:
looking for [pearl jam: even flow]
node found! pearl jam: even flow
looking for [pearl jam: daughter]
node not found
====================================

Testing find_artist:
looking for [pink floyd]
artist found! pink floyd: time | radiohead: paranoid android | radiohead: street spirit (fade out) | 
looking for [pearl jam]
artist found! pearl jam: alive | pearl jam: even flow | pearl jam: yellow ledbetter | pink floyd: time | radiohead: paranoid android | radiohead: street spirit (fade out) | 
looking for [presidents of the united states of america]
artist not found
====================================

Testing songcmp (helper function):
Comparing [pearl jam: even flow] to [pearl jam: even flow]
0
Comparing [pearl jam: even flow] to [pearl jam: alive]
4
Comparing [pearl jam: alive] to [pearl jam: even flow]
-4
Comparing [pearl jam: even flow] to [pink floyd: time]
-4
====================================

Testing random:
radiohead: paranoid android
radiohead: street spirit (fade out)
radiohead: street spirit (fade out)
radiohead: paranoid android
====================================

Testing remove:
Removing [pearl jam: alive]
ac/dc: thunderstruck | pearl jam: even flow | pearl jam: yellow ledbetter | pink floyd: time | radiohead: paranoid android | radiohead: street spirit (fade out) | 
Removing [pearl jam: yellow ledbetter]
ac/dc: thunderstruck | pearl jam: even flow | pink floyd: time | radiohead: paranoid android | radiohead: street spirit (fade out) | 
Removing [pink floyd: alive]
pearl jam - alive not found
ac/dc: thunderstruck | pearl jam: even flow | pink floyd: time | radiohead: paranoid android | radiohead: street spirit (fade out) | 
====================================

Testing free_list
freeing node: ac/dc - thunderstruck
freeing node: pearl jam - even flow
freeing node: pink floyd - time
freeing node: radiohead - paranoid android
freeing node: radiohead - street spirit (fade out)
list after free_list:

====================================

MUSIC LIBRARY TESTS

====================================

Testing print_library
a list
ac/dc: thunderstruck | 
p list
pearl jam: alive | pearl jam: even flow | pearl jam: yellow ledbetter | pink floyd: time | presidents of the united states of america: peaches | 
r list
radiohead: paranoid android | radiohead: street spirit (fade out) | 
====================================

Testing print_letter
p list
pearl jam: alive | pearl jam: even flow | pearl jam: yellow ledbetter | pink floyd: time | presidents of the united states of america: peaches | 
====================================

Testing find:
looking for [pearl jam: alive]
song found! pearl jam: alive
looking for [pearl jam: time]
song not found
====================================

Testing find artist:
looking for [pearl jam]
artist found! pearl jam: alive | pearl jam: even flow | pearl jam: yellow ledbetter | pink floyd: time | presidents of the united states of america: peaches | 
looking for [pink floyd]
artist found! pink floyd: time | presidents of the united states of america: peaches | 
looking for [bob dylan]
artist not found
====================================

Testing remove_song
removing: [pearl jam: alive]
a list
ac/dc: thunderstruck | 
p list
pearl jam: even flow | pearl jam: yellow ledbetter | pink floyd: time | presidents of the united states of america: peaches | 
r list
radiohead: paranoid android | radiohead: street spirit (fade out) | 

removing: [pearl jam: yellow ledbetter]
a list
ac/dc: thunderstruck | 
p list
pearl jam: even flow | pink floyd: time | presidents of the united states of america: peaches | 
r list
radiohead: paranoid android | radiohead: street spirit (fade out) | 
====================================

Testing clear_library:
freeing node: ac/dc - thunderstruck
freeing node: pearl jam - even flow
freeing node: pink floyd - time
freeing node: presidents of the united states of america - peaches
freeing node: radiohead - paranoid android
freeing node: radiohead - street spirit (fade out)

Library after clear:
====================================

Adding songs to empty library
a list
ac/dc: thunderstruck | 
p list
pearl jam: alive | pearl jam: even flow | pearl jam: yellow ledbetter | pink floyd: time | 
====================================

Testing print_artist:
Printing [pearl jam]
[pearl jam: alive]
[pearl jam: even flow]
[pearl jam: yellow ledbetter]

Printing [ac/dc]
[ac/dc: thunderstruck]
====================================

Testing shuffle
ac/dc: thunderstruck
ac/dc: thunderstruck
pearl jam: yellow ledbetter
====================================

1-10 of 19