--- tags: School --- # Assignment 1 #### By Bryan Peppers & Jason Scott ## 1 Linux Installation ### 1 Installed Debian 10.0 'buster' on the Linux-9 computer in the EIB309 lab. Did not stray from the default installation options much. Though we did install the Xfce gui. Created an account for each person in the group and for Professor Lauter by logging into 'su -' using the password we created. Then 'useradd {name}; passwd {name}' to create the account and set the passwords. ### 2 Made sure the ssh worked for the system by retrieving the ip address using the command "ip a". Then from my personal laptop on the University vpn, I was able to ssh into the system using the command 'ssh bwpeppers@137.229.182.157'. ### 3 Using command 'apt install gcc gdb make emacs' we installed everything we need to compile a program written in C. The man pages already seemed to be installed, as the 'man 2 open' commands works without a hitch. ### 4 The IP address of the machine is 137.229.182.157. ## 2 Getting to know the *bash* shell ### 1 We logged into the tikishla system, using the command: ```bash ssh csce321@tikishla.duckdns.org ``` Entering the given password when prompted. ### 2 * Using the 'w' command, the systems only user was us at the time. * Using 'uptime' command, the system has been on for 65 days. * Using 'cat /proc/cpuinfo' command, the system has 4 AMD Opteron(tm) Processor 280s. * Using 'free -m' command, the system has 2886MB of RAM. * Using 'ip a' command, the systems active ip was 137.229.168.214. ### 3 Used the command 'scp nanpa bwpeppers@137.229.182.157:/home/bwpeppers/Documents' to transfer the file back to our home system. ### 4 Found the entry for '907519' using less by searching in less using '/907519', which was 907519Anchorage AK. Found the entry for '503526' using less by searching in less using '?503526', which was 503526Beaverton OR. Using same methods found entry for '907338', which was 907338Anchorage AK. Using same methods found entry for '808334', which was 808334Hilo HI. ### 5 Using the command 'wc -l nanpa', found there are 166482 lines in the nanpa file. ### 6 Used 'head -17 nanpa' to list the first 17 lines of the nanpa file. Used 'tail -42 nanpa' to list the last 42 lines of the nanpa file. ### 7 ```bash #!/bin/bash if [[ $# -ne 1 ]]; then >&2 echo "Invalid number of parameters."; exit 2; fi charcount=$(echo $1 | wc -m) if [ $charcount != 7 ]; then >&2 echo "Wrong argument length"; exit 1; fi if ! [[ "$1" =~ ^[0-9]+$ ]]; then >&2 echo "Only 6 digit integers"; exit 1; fi line=$(grep $1 nanpa) if [ -z "$line" ]; then >&2 echo "Prefix not found"; exit 1; fi output=$(echo $line | sed 's/[0-9][ \t]*//g') echo $output ``` The above code is my script for to find the location for the given prefix. It expects a 6 digit integer as a command line argument, and then finds the location of that prefix in the nanpa file. If the argument passed is incorrectly formatted or if the prefix is not found it exits with code 1. If it is found it formats the location and outputs it to stdout. If more or less than one parameter is passed to the script, it exits with code 2. ### 8 When testing this findlocation.sh script, I found almost all searches took from 0.021 sec to 0.024 seconds to complete. I could not find a test where one search took a noticably longer or shorter time. Complexity of a binary search alogorithm is O(log n), which would most likely be best for this case, as the list is sorted. However grep uses the Boyer-Moore algorithm which has a worst case of O(nm), but generally can be said to have a linear runtime. ## C toolchain test ### 1 Subdirectory "code" was created in /home/jscott and endless.c created with provided code (file also attached). ```C #include <stdio.h> int main() { unsigned int a, b; volatile unsigned int c; a = 0u; c = 0u; while (1) { printf("%u\n", a); for (b=0u; b<(1u<<30); b++) { c++; } a++; } return 0; } ``` ### 2 Code compiled with "gcc endless.c -o endless -O3"; -o to set output file name, and -O3 to set optimization level to 3. ### 3 Opening top in another ssh'ed terminal shows 100% CPU usage for "endless" process. ### 4 Endlesssleep.c created with provided code (file also attached). ```C #include <stdio.h> #include <unistd.h> int main() { unsigned int a; a = 0u; while (1) { printf("%u\n", a); sleep(1); a++; } return 0; } ``` ### 5 Code compiled with "gcc endlesssleep.c -o -endlesssleep -O3"; -o to set output file name, and -O3 to set optimization level to 3. ### 6 Opening top in another ssh'ed terminal shows 0% CPU usage for "endlesssleep" process (had to show only processes from user to see it). ### 7 The "endless" program uses a lot more CPU because of the time spent incrementing between printing (to cause a pause between printing the numbers), while "endlesssleep" sleeps instead (telling the CPU to wait for a specified duration). I.E. In the 'endless' program, it never reliquishes the cpu between prints, while the 'endlesssleep' program, reliquishes the cpu between prints with the sleep command.