User Tools

Site Tools


opus:fall2011:kkrauss1:start

Table of Contents

Karl Krauss

FALL 2011 OPUS

Introduction

My name is Karl Krauss, I have a degree in Math/Science and currently working on Comp Sci and HPC.

Part 1

Entries

September 20, 2011

  • Fourth week of school and I feel like I have gotten nothing done. I am trying to get a couple of systems up and running to take up to campus for Joe O's office. I am testing some harddrives as well, all of this is an hpc project. Keywords are killing me, I have 36 to get done before the end of the month, 12 for each class, and I only have 5. Looking through them is teaching me new things, but thats for the c/c++ class, data structs and sys prog I do not even know where to begin.

September 21, 2011

  • So after spending almost 12 hours in the lair yesterday, I feel like I might have actually accomplished something. Albeit not nearly enough by my standards. Going through the keywords has been tedious and slow at points but the tedious and slow research is usually where you learn the most. I did a couple of interesting experiments dealing with floats and pointers. The one dealing with pointers was meant to help others understand them a little easier but it had the added effect of solidifying my basic understanding. I also tested a few dozen hard drives in an effort to get a modicum of organization going. I was able to get two units up and running for joes office which I will take up today. Now its time to tackle some more topics.

September 26, 2011

Today was a good day for many reasons. It seems like my C is coming together, though I admit I know there is still a long ways to go. The best part was with my structure pointer experiment which actually proved Joe O. wrong. A very difficult task to say the least. Today I am going to do my best to finish up my keywords and work on some objectives.

September 26, 2011(later)

Ok so the sysprog book is a bit rough(though not as rough as the discrete book) but I finally finished enough keywords for the month. Some of them I didnt really grasp, such as bit sets and bit masks. Others were a little easier for me(assuming I am right): inodes and data blocks. Hopefully some of this stuff will become easier to understand as we go on. Most things seem to becoming easier but a few still need work.

CPROG Topics

Keyword 1: Standard I/O

Standard I/O(standard input/output) Just as its name implies it deals with inputing information to the terminal, and inputing input from the keyboard

  • STDIN(Standard Input): Deals with reading whatever text is typed(input)
  • STDOUT(Standard Output): Prints requested information to the screen(output)
  • STDERR(standard Error): Is specifically designed for printing error messages(error output)
#include <stdio.h>
 
int main()
 
{
 
 
 
		int number;
 
 
 
		printf("Please enter a number: "); //this is standard output
 
		scanf("%d", number); //this is standard input
 
		fprintf(stderr, "this goes to STDERR\n"); //this is standard error(output)
 
 
 
	return 0;
 
}

Keyword 2: Header files

Libraries for the C/C++ language are actually made up of two parts. The header files that declare, and the actual library or “archive” that contains the definition. The library(“archive”) will be discussed later.

The Header files is “included” in a programmers code and allows for easy access to predefined functions. System header files are part of the C/C++ standard library. Local ones are ones defined by the programmers. Most beginning programmers use header files from the C/C++ standard library before they even know exactly what they are.

#include <stdio.h> 
// This is how you include a standard library header file(system) and is almost always used in some way
#include "myheader.h" 
// This is how you include a local header file defined by a user

Keyword 3: Arithmetic(operators and equations)

Arithmetic is defined as dealing with the manipulation of numbers. The basic necessity of arithmetic is operators. The basic operators are (+), (-), (*), (/), and the less known(%).

  • (+) is addition
  • (-) is subtraction (addition of a negative number)
  • (/) is division
  • (*) is multiplication
  • (%) modular division. This is the same as division but the remaining(left over) number from standard division is what is used.

Equations are simply a combination of operators and numbers

#include <stdio.h>
 
int main()
{
    int a = 5, b = 6; 
	float c = 0;
 
 
    printf("a = 5, b = 6 \n");
    c = a + b; // equation using the (+) addition operator
    printf("a + b = %.2f\n", c);
 
	c = a - b; // equation using the (i) subraction operator
	printf("a - b = %.2f\n", c);
 
	c = a * b; // equation using the (*) multiplication operator
	printf("a * b = %.2f\n", c);
 
	c = (float) a / (float) b; // equation using the (/) division operator
	printf("a / b = %.2f\n", c);
 
	c = a % b; // equation using the (/) modular division operator.  
	printf("a %% b = %.2f\n", c);
 
 
    return(0);
}

Keyword 4: Bitwise Operators(and, or, not ,xor)

As defined by Practical C programming, 3rd edition, an Operator: is a symbol that represents an action to be performed.

Bit operators allow us to work on the individual bits of a data type. Thus far I have not seen them used too much but it is important to know what they are. It will also make it clear why the equivalent logical operators are symbolized the way they are.

  • & bitwise and
  • | bitwise or
  • ^ bitwise exclusive(does not have an equivalent logical operator)
  • ~ complement (does not have an equivalent logical operator)
  • « shift left (does not have an equivalent logical operator)
  • » shift right(does not have an equivalent logical operator)

resources

  • Chapter 11 of Practical C programming, 3rd edition

Keyword 5: Variables(types,ranges, sizes)

Variables are simply memory locations that are given names and can be assigned values. Variables are used to store different types of data in memory for future usage.

The two basic variable types are Numeric and character.

  • Numeric has several subtypes and can be integers or real values
  • characters are letters, ASCII symbols, and even 0-9

Here is a list of data types and their range. (this list assumes signed integers, you can add unsigned to the data type shifting the range, size stays the same)

short Numeric - Integer signed: -32768 to 32767 unsigned: 0 to 4294967295 int Numeric - Integer signed: -2147483648 to 2147483647 unsigned: 0 to 4294967295 long Numeric - Integer signed: -2147483648 to 2147483647 unsigned: 0 to 4294967295 float Numeric - Real signed: 1.2 X 10-38 to 3.4 X 1038 no unsigned double Numeric - Real signed: 2.2 X 10-308 to 1.8 X 10308 no unsigned char Character signed: -128 to 127 unsigned: 0 to 255

These values are all relative to the operating system, as is the same for the size. A char is typically one byte but that might not always be the case. Programmers should always use the sizeof() function to determine the size of the variable type they wish to use.

example:

#include <stdio.h>
 
int main()
{
     int a = sizeof(int),b = sizeof(short),c=sizeof(char):
 
     printf("int: %d\n", a);
     printf("int: %d\n", b);
     printf("int: %d\n", c);
 
 
 
     return 0
}

Keyword 6: Strings

From wikipedia: a string is a finite sequence of symbols that are chosen from a set or alphabet.

For example: this entire sentence could be considered a string or several strings being printed in a certain order. In the C++ language their is an actual string variable but the C language does not have one. C handles strings by simply using an array of characters(which is really what a string is: an array of characters). In the example code I will declare an array and set it equal to a word, this can be one with pointers as well and will be discussed in the future.

example:

#include <stdio.h>
 
int main()
{
	char string[6] = "Hello";  /* array of characters with six elements is declared and set equal to "Hello"
		quotes are not stored but needed to store multiple characters.  The six element is needed as the string
		terminator.  arrays will be gone into greater depth in the future. */
 
	printf("%s\n", string);  //this is printing the string(array of characters) to the screen
	printf("The string is: %s\n", string); //This is printing a literal string and then the stored string(array of characters)
 
        return 0;
}

Keyword 7: Pointers(address of, assignment, dereferencing)

  • Pointers were dealt with in data structures.

Keyword 8: Version control

Keyword 9: Structures

  • Structures were covered in Data structures keywords

Keyword 10:Scope( local, block, Global, File)

Scope of a variable is the portion of a program in which a variable is known

  • Global variables are outside of all functions and can be used by all functions and blocks(everywhere).
  • Local variables are inside a block
  • A block is a section of code enclosed in braces. {}
  • File scoped variables act just like Global variables except they can only interact with the file they were declared in.

Keyword 11 Type Casting

Type casting is when you make a variable of one data type act like another type for a single operation. To cast a variable name simply use brackets() in front of the variable and include inside them the temporary variable type you wish to use. Here is some example code:

include <stdio.h>
 
int main()
{
        int variable = 97;// decarling a variable of int type and giving it value
        printf("%d\n", variable);// simply printing the value of variable as it is
        printf("%c\n", (char)variable);// casting variable as a character should give the ascii char value of 97
 
        return 0;
}

Here is the output:

lab46:~$ ./a.out 
97
a

I would just like to add that with printf() you actually do not need to cast in this particular case but it gets the point across.

Keyword 12: Arrays

Arrays were covered in Data structs.

DATA Topics

Keyword 1: Version control(checkout, commit, update, add, log)

Version control is, simply put, a repository of files. Any change made to the source file is tracked and can be reversed if necessary. Wikipedia is an example of version control, if some one makes an improper change to a page, the original information is not lost it is stored as the previous version therefore making it easy to be restored.

  • Checkout: is when a user opens up a file from the repository and creates a local working copy. A user can typically call any previous revision or the latest.
  • commit: the opposite of checkout, is when the user writes or merges the changes they made in the local copy back to the repository.
  • update: similar to commit but in reverse order, the user merges any changes to the the source file with the local copy.
  • add: this is simply adding a new file to the repository.
  • log: is a log of changes made to a source file along with time stamp and any messages entered when committed.

Very helpful resource.

Keyword 2: Pointers(address of, assignment, dereferencing)

Pointers are data types whose value refers to another value stored elsewhere. When you declare a variable that is a pointer you are simply storing an address in that variable that has the data you want. The address that is pointed to is often called the pointee.

  • assignment: makes two pointers point to the same pointee.
  • dereferencing: Is storing a value in the pointee.
  • address of: the address of a pointer(&pointer) is the address that the pointee address is stored at.

Here is an experiment I did that deals with pointers.

Keyword 3: Structures

  • In the past if we have used arrays for storing a group of data. Structures basically do the same thing but with an added benefit that arrays do not have. Arrays can only store the same data type but with structures you can have a mixed bag of data types.
  • To declare a structure called “date” that has 3 variables, 2 are int's and 1 is an array of char's:
struct birthDate {
     int year, day;
     char month[10]; 
};  // the structure is now declared
  • After the structure called “birthDate” has been declared you can now declare as many “birthDate's” as you want.
struct birthDate Karls; //Now we have declared a variable called Karl witch is a structure of the birthDate type.
Karls.year = 1988; //we've set Karls birthyear to 1988(lies) 
  • You can create as many structs of the birthDate type as you want and set each variable type INSIDE of EACH struct to whatever you wish. It definitely has its advantages over arrays.

resources

Keyword 4: Structure pointers

  • Now for the infamous structure pointer, the cold hearted beast who will torment you until you smash your shiny new monitor but will eventually become your best friend(we aren't quite there yet). Pointers to structures change things a bit and even have their own special operator.
  • Using my previous example from structures lets say we declared a pointer to struct birthDate:
struct birthDate *Brad;  // we have declared a variable named Brad which POINTS to a structure  of the birthDate type
  • Dont freak out its almost over, and in reality quite simple, it just needs to be done repeatedly, like anything fun, to really get it.
  • So now how would you think to change the variable year?
(*Brad).year = 1999;// this SHOULD work(in theory)
Brad->year =1999;// this WILL work and is known as the structure pointer
  • Thats it, all a structure pointer is (→).

resources

Keyword 5: Arrays

Much like structures, arrays are used to manage a large quantity of data. The difference is: an array cannot mix data types. If you have multiple data types you will need to use an array for each. Arrays are declared the same way you declare many other data types except they have an index added to end signified by the []. For example:

void main()
{
 
     char array[10];  //I just declared a ten element array of the data type char
     array = "september";// now I have stored 9 characters within the array.
}
  • The reason i only stored 9 characters in my array is when dealing with “strings” you need to have a null terminator.

To access individual elements of the array you simply use the index, which typically starts at 0. array[0] = s, array[1] = e, array[2] = p. This is quite handy if you need to call one particular element of an array.

Keyword 6: Null pointer

A null pointer simply pointers “nowhere”. And uninitialized pointer can pointer virtually anywhere(but unknown), but a NULL pointer points nowhere meaning there is no object associated with the pointer. Setting a pointer equal to null is quite easy. Example:

{
 
     char *variable = NULL; // all done, yes it's THAT easy for me, it can be this easy for you too!
 
}

Keyword 7: Void pointer

A Void pointer is a way to deal with raw memory. Void basically means the absence of a data type. Void pointers also allow for passing a pointer to an unspecified type.

Keyword 8: Function pointers

Function pointers are an interesting concept and, at least for me, a difficult one to understand. I only recently learned of them so I am not sure how strong this entry is going to be. In simplest terms(Joe O. is going to hate this) a Function pointer is a pointer to a function; AKA: a pointer that points to the address where the function is at. They can be used when you are not sure which function you wish to call. As my understanding is limited I will simply link to a better written explanation of function pointers.

Function pointers

Keyword 9: Static allocation vs. dynamic alocation

static allocation is when memory is allocated before a program is executed(compile time)

Dynamic allocation is when memory is allocated as needed during run time.

Keyword 10: Memory allocation, malloc(),new

Malloc() is a function in C that allocates memory and returns the beginning address. new is a keyword for c++ and basically does the same thing malloc() does for c.

{
    int *variable;//declaring a pointer to an int
 
    variable = malloc(sizeof(int)); //allocating memory for the variable
 
}
 
{
    int *variable;//declaring pointer
 
    variable = new int;// and again allocating memory for the variable
 
}

Keyword 11: memory de-allocation free(),delete

free() and delete are the opposite of malloc() and new free() is a function in c that will de-allocate memory that was previously allocated, so that it can be used if needed. delete is a keyword in c++ that will do the same.

Keyword 12: Linked lists

Linked lists lists is a sequence of nodes and each node points to the next one i the sequence. Linked lists are nice when you do not know how big the sequence(list) is going to be and allows for virtually infinite growth.

SYSPROG Topics

Keyword 1: UNIX systems programming

Unix systems programming, in part, is the understanding the role of an OS as well as what it means to write programs that work directly with the operating system.

sources

first page of the sysprog book that I took off of Haas' desk.

Keyword 2: Kernel space

Kernel space is where the kernel, its extensions and many drivers run. The kernel is the core of the operating system.

Keyword 3: User space

User space is where everything outside of the kernel space is run(everything not related directly the operating system).

Keyword 4: File access(open, read, write, lseek, close

File access is how you access and manipulate files. To do so you need certain tools:

  • Open is a system call used for creating a connection to a file. If there is an error a -1 will be returned, if everything works according to plan a positive integer will be returned which will be the file descriptor.
  • read is a system call used for reading the data in a file, it can be the entire file or a certain amount of bytes.
  • close is a system call that closes the connection to the file
  • write is a system call that copies information from memory to the file
  • lseek is a system call that sets the current position for the file to a defined position.

Keyword 5: file descriptors

A File descriptor is a connection created between a process and a file when the open system call is used.

Keyword 6:Buffering

Buffering is reading data in large sizes into memory from user space and then processing it in smaller pieces as the user needs it.

Keyword 7:System call

A System call is a request from a program for a service of the operating system(kernel).

Keyword 8:File types and file properties

Everything in unix is a file. There are several file types: Directories, regular files, and links. Each file has certain properties which can be seen in unix using ls -l(this will tell you the file type as well). The properties are: permissions, owner, group, size of the file, date of last modification and name of the file.

Keyword 9:Bitset and bit masks

A bitset is when a bit or group of bits are “set” to 1(true) via a bitmask. A bit mask is used for setting bits to 1 or 0, or to keep a certain section of bits.

Keyword 10:User ID's, Group ID's

The owner and group of a file are stored as numbers which are the User ID and Group ID. The superuser always has a value of 0, everyone else gets a non-negative integer.

Keyword 11:Filesystem structure, inodes and data blocks

The Unix Filesystem from a users viewpoint is a tree structure. It branches out with each directory and new file. An inode is a struct that stores the properties of each file. Data blocks are where the actual contents of files are kept. Blocks are the same size and one file can use as many as is needed.

Keyword 12:Directories

A directories is simply a file that contains a list of names of files along with a table of inode numbers for those file properties.

links in Unix are very similar to shortcuts in windows. It is like having multiple phonebook entries in several places. A link is simply a special file that points to another file.

HPC1 Topics

Keyword 1

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
    return(0);
}

Keyword 2

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you want to demonstrate something on the command-line, you can do so as follows:

lab46:~$ cd src
lab46:~/src$ gcc -o hello hello.c
lab46:~/src$ ./hello
Hello, World!
lab46:~/src$ 

Keyword 3

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
    return(0);
}

Keyword 4

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you want to demonstrate something on the command-line, you can do so as follows:

lab46:~$ cd src
lab46:~/src$ gcc -o hello hello.c
lab46:~/src$ ./hello
Hello, World!
lab46:~/src$ 

Keyword 5

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
    return(0);
}

Keyword 6

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you want to demonstrate something on the command-line, you can do so as follows:

lab46:~$ cd src
lab46:~/src$ gcc -o hello hello.c
lab46:~/src$ ./hello
Hello, World!
lab46:~/src$ 

CPROG Objectives

Objective

  • To understand the basic concepts of arrays and pointers.

Q&A

Arrays

What is an array? *An array is a set of consecutive memory locations used to store the same type of data.

What are arrays used for?

  • Arrays are used for many things but typically they are used for strings and anytime you have a large quantity of values that are all the same data type

How do you declare an array?

  • Arrays can be declared like any other variable except the variable name is followed by []. This is called the index and is how you would access any element of the array

Pointers

What is a pointer?

  • A pointer is simply a data type that instead of storing a value actually stores another address which in turn has the value

What are pointers used for?

  • Pointers not only can be used much like arrays but are also easy to use for pass data to a function. As a memory address is easy to pass and a variable is not.

How do you declare a pointer?

  • Pointers can be declared like any other variable except the variable name is preceded by *. This tells the compiler the variable is actually pointing to the data type and is not actually the data type. A pointer is its own data type. Pointers do not have an index.

DATA Objectives

Objective 1

Some common applications for linked lists:

  • filesystem's
  • database tables

SYSPROG Objectives

Objective 1

Concurrency:

  • Concurrency is when several processes are running at the same time and can possibly interact with each other.
  • If not handled correctly a processes can be forever waiting for each other to release a resource(deadlock) or can be continually denied a resource(starvation)

HPC1 Objectives

Objective 1

State the course objective; define what that objective entails.

Method

State the method you will use for measuring successful academic/intellectual achievement of this objective.

Measurement

Follow your method and obtain a measurement. Document the results here.

Analysis

Reflect upon your results of the measurement to ascertain your achievement of the particular course objective.

  • How did you do?
  • Room for improvement?
  • Could the measurement process be enhanced to be more effective?
  • Do you think this enhancement would be efficient to employ?
  • Could the course objective be altered to be more applicable? How would you alter it?

Objective 2

State the course objective; define what that objective entails.

Method

State the method you will use for measuring successful academic/intellectual achievement of this objective.

Measurement

Follow your method and obtain a measurement. Document the results here.

Analysis

Reflect upon your results of the measurement to ascertain your achievement of the particular course objective.

  • How did you do?
  • Room for improvement?
  • Could the measurement process be enhanced to be more effective?
  • Do you think this enhancement would be efficient to employ?
  • Could the course objective be altered to be more applicable? How would you alter it?

Objective 3

State the course objective; define what that objective entails.

Method

State the method you will use for measuring successful academic/intellectual achievement of this objective.

Measurement

Follow your method and obtain a measurement. Document the results here.

Analysis

Reflect upon your results of the measurement to ascertain your achievement of the particular course objective.

  • How did you do?
  • Room for improvement?
  • Could the measurement process be enhanced to be more effective?
  • Do you think this enhancement would be efficient to employ?
  • Could the course objective be altered to be more applicable? How would you alter it?

Semester Experiments

Experiment 1

Question

Will C allow for unsigned floats?

When looking up information on the ranges of data types I noticed there was never an unsigned range for floats, so I thought I would look into it. I am going to copy simple code trying to define unsigned floats and then copy the outcome of my attempt to compile

#include <stdio.h>
 
int main()
{
	float a = 5.0;  // To show the compiler will have no issue declaring a float and setting it equal to a value
	unsigned float b = 10.0; // to show the compiler will treat 'unsigned' and 'float' as two separate keywords that do not belong together
							// this will be seen in the messages after attempting to compile
	printf("float = %f\n unsigned float = %u\n", a, b);  // this is to remove other warnings when compiling 
 
	return 0;
}
lairstation3:~/Desktop/experiments$ gcc -Wall canfloatsbeunsigned.c 
canfloatsbeunsigned.c: In function ‘main’:
canfloatsbeunsigned.c:6: error: both ‘unsigned’ and ‘float’ in declaration specifiers

As you can see it simply won't work, it does not compile. My research leads to a very simple answer. There is no equivalent machine code operations for the cpu to execute(the cpu is not designed to deal with unsigned floats). The url below has discussions on the subject.

Resources

Pointers, address of, value at)

Question

I have noticed that pointers are often times a hurdle for beginning programmers. A common question I hear is: what is the difference between * and &. Early on in the learning process many people do not know what “varName” is when “char * varName” is declared. I am going to attempt to remedy this.

  • I am going to show you some code and the output of that compiled code, pay close attention to the notations before moving onto the conclusion
#include <stdio.h>
#include <stdlib.h>
 
int main()
{
	char *varName;// I declared a variable called varName that is a pointer aka (*) to a char
	varName = malloc(sizeof(char));  //Malloc returns an address and sets varName = to it(sizes it as well)
	*varName = 'a';// I set *varName(the value AT varName) = 'a'
 
	printf("varName = 0x%x\n",(int) varName);  // "varName" is a pointer to a char, meaning whatever address pointer is at, has ANOTHER address stored there
	printf ("*varName(the value at pointer) = %c\n", *varName);// the address that is stored in varName has a value stored and this is how you get it
	printf("&varName(the address of) = 0x%x\n", (int) &varName);// "varName" is at an address and this is how you get it
 
 
	return 0;
}
  • after compiling and running the code this is what will be seen:
lairstation3:~/Desktop/experiments$ ./a.out 
varName = 0x98c5008
*varName(the value at pointer) = a
&varName(the address of) = 0xbfa0b90c
lairstation3:~/Desktop/experiments$ 

Conclusions

  • If you read info on the keyword variables you will see that a variable is simply a memory location that is given a name and can be assigned a value. When you declare a pointer(*) you are simply giving a memory address a name and then storing ANOTHER memory address in it.
  • This is why “varName” prints out an address, because an address is what is stored AT the address we named “varName”.
  • The reason you get a value(a character in my example) when you print “*varName”(the value AT varName) is because we are asking for the data that “varName” POINTS to(varName is a given name for an address, we asked for the information that was stored at the address stored within varName).
  • Now you also get an address when you print “&varName”(the address of) but that address is different than “varName”. This is because “&varName” gives the actual address that “varName” is stored at(varName is just the name of an address and the & operator simply asks for it).
  • Hopefully this is starting to make sense(feedback welcome). If it is try to answer(and understand) this question for yourself: what happens if you print “*&varName”

Structure pointers

Recently I got into a debate involving structure pointers. This is to show exactly what a struct pointer is:

#include <stdio.h>
#include <stdlib.h>
 
struct bin {
                char *string; 
        };
int main()
{
        struct bin *joesWrong;// declaring a pointer to a struct of the type bin
 
        joesWrong = malloc(sizeof(struct bin)); //mallocing up the struct
 
        joesWrong->string = malloc(sizeof(char)*20);  //these next two lines mean the same
        (*joesWrong).string = malloc(sizeof(char)*20);// and will be proven  in the next block of code
 
 
 
        joesWrong->string = "karl's right\n"; // we will see that the following code works as it should
        printf("%s\n", joesWrong->string);  
        (*joesWrong).string = "Joe's wrong\n"; // this means that x->y and (*x).y mean the same thing
        printf("%s\n", (*joesWrong).string);
 
 
        return 0;
}

This is the output of the code, and as you will see it works as expected, thus showing exactly what a function pointer is. x.(*Y) != x→y

karl's right

Joe's wrong

lab46:~$ ^C
lab46:~$ 

This is a link for Joe :)

Part 2

Entries

October 5, 2011

  • Finally have a solid understanding of doubly linked lists and have a libary of basic functions. I am going to attempt to either write a stack using current library or modify my doubly linked list library to better suit a stack. There honestly just seems like there is too many things to do in such a short period of time. The opus for the first month was quite extensive and I only finished because I did a mediocre job on some of the objectives and keywords. I havent even done any projects for data comm, and am a little behind in discrete(programming functions in c). Hopefully I can be more productive this month.

October 5, 2011

  • Ok so I am confident I understand the concept of a stack, in fact the concepts are usually the simple part. I took the library I made for a doubly linked list(another simple concept yet difficult to implement) and combined it with the basic code we did in class for stacks. I had to make some changes but it functions as it sits. Now if I can make some progress in other areas I will be good.

October 14, 2011

  • Fashizzle, its time to take my stack library and convert it into a queue library. Certain things seem to be getting easier, but there is still sooooooooo much work to do, I do not know of a single student who does not think the work load is a bit extreme. The learning is great but its getting to be quite stressful to keep up.

October 31, 2011

  • So it is that time, the end of the second part of the opus is upon us. We are moving into binary trees. The concept, as usual, is quite simple. Let's just see how simple the implementation of the concept really is. For the most part classes are going well but in many I have hit a brick wall and feel a lack of direction. I just hope I can get it all figured out before the end of the semester.

cprog Topics

Keyword 1: Selection Structures

  • Selection structures AKA if statements(case/switch) is a key element in virtually any programming. It allows you to select a specific path to follow in your code.

Example code:

#include <stdio.h>
 
int main()
{
	int number;
 
	printf("Please enter a number between 1 and 10: ");
	scanf("%d", &number);
 
	//here is the selection statement
	if (number < 5 && number >= 1)
	{
		printf("You entered a number between 1 and 4\n");
	}
	else if (number >=5 && number <=10)
	{
		printf("\nYou entered a number between 5 and 10\n");
	}
	else
	{
		printf("\nYou entered an invalid number.\n");
	}
 
	return 0;
 
}

Keyword 2:Repetition/iteration structures

  • Repeition/iteration structures allow you to do a specific task a set number of times. For loops and while loops are how these are done.

Example code:

#include <stdio.h>
 
int main()
{
	int number = 10;
	int x;
	printf("\n");
	for(x = 1; x <= number; x++)
	{
		printf("%d\n", x);
	}
 
 
	return 0;
 
}

Keyword 3: Multi-Dimensional arrays

  • Multi-Dimensonal arrays much like single dimensional arrays are used for managing large amounts of data. As with any array the data type has to be the same however with Multi-Dimensional you can store several instances of data. Another way to think of it is to say an array of arrays. A single dimensional array has one index noted by array[] where as multi dimensional will have more than one group of brackets. Here is an example of a two dimensional array, char names[5][10]. This could be used to store 5 different strings with a max of 9 characters per string(the tenth being the null terminator).

Keyword 4:File access

File access was covered in Sys prog.

Keyword 5:typedef, enum, union

  • Typedef allows us to define our own variable types. As an example it is often used with structures. When you define a structure and give it a name(struct example) you will need to type struct example every time you declare a new version. But if you typedef it to say myStruct, then you can just type myStruct.
  • enum defines an enumerated data type which is a way to give a group of variable names a const num value instead of manually setting each variable equal. enum day_of_the_week {SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY,FRIDAY, SATURDAY}; Sunday = 0, monday =1, etc.
  • Union allows for different data names and types to be assigned to the same storage location. Similar to a structure except now only one variable can be store at a time. You might declare an int and a char within a union but only one can have a set value at any given time, never both.

Keyword 6: Functions

  • Functions are simply blocks of code that perform a specific task, and typicall(not always) return a value.

Keyword 7: Parameters

  • Parameters are often used to pass information to a called function. In C they can be passed by value or by address. In other words you can actually pass the value of a specific variable(aka int) to a function, or pass an address, passing by address allows you to pass more data since you can point to data structures.

Keyword 8: return types

  • Functions in C will typically be written to return some value. Any valid data type can be returned, including pointers. Programmers will often have functions return a data type as a way to use it in the main program, or some other function. They will also often return a basic int value to check and see if the function completed properly.

Keyword 9: Recursion

  • Recursion is when a function calls itself. Basically it is when a function is called to run before it is finished. This it to be typically avoided as it can lead to memory access problems.

Keyword 10: Command line arguments

  • Command line arguments/options allow for certain options of program to be run from the command line. To use this ability you would use argc and argv in main. Lets say you have a program that takes a string and appends it to another, you can run the program then prompt the user to enter each string, but with argc and argv it would allow the user to type the name of the program a space, the first string, a space the second string and the program will do its job without being prompted.

Keyword 11: Code stages(source,object, Binary)

  • Code typically goes through stages that start with what the programmer writes, all the way down to an executable program.
  • source code is what the user writes in human readable language
  • object code is source code that has been compiled as it was written in source, it has not been linked to any included libraries
  • binary code is the final stage and is compiled object code that has now been linked to all necessary libraries and can be run if coded properly

Keyword 12: Compiler, preprocessor, flags, assembler, linker

  • When first learning how to take your source code and make it a runnable program we often say we are compiling, but in fact there are several things that happen when compiling a program. When using the compile program(in this example we will use gcc) the first step is to add any flags you might want. These are basically command line options that allow you to compile the program exactly how you want to. Ex: give a specific name, compile with warnings, add debugging options etc etc. After the compiler is started the source code first gets passed by the preprocessor this is what processes any includes, conditional compilations instructions and any macros. Then what the preprocessor gives us is passed by the compiler which takes all of that code and turns it into assembly language. At this point the assembly version of our code is passed by the assembler which turns it into an object file. We are almost done but first we need to take our object file and link it to any needed libraries to make it binary, and this is done with the linker.

data Topics

Keyword 1: Doubly Linked Lists

Doubled linked lists are not much different than linked lists except now each node not only points to the next node but to the previous as well.

Keyword 2: Stacks(array and linked list based)

A stack is a last in first out data structure, meaning the “top” of the stack is all you have immediate access to. You can store data on top of the stack, remove it, or view it.

  • An array based stack you would use an array of whatever data type you wanted and the last element of the array that has a stored value would be the top of the stack
  • A link list based stack uses “nodes” and the last node is the top of the stack

Keyword 3: Pushing

Pushing is when you add to the top of a stack or initializes the stack if it is empty

Keyword 4: Popping

Popping simply removes the data stored at the top of the stack.

Keyword 5: Top(stack top, peek, whatever you wish to call it)

Top typically simply returns the value at the top of the stack but does not delete it like pop does.

Keyword 6: Overflow Condition

Overflow is when a stack is full and cannot accept anymore data

Keyword 7: Underflow condition

Underflow is when the stack is empty and there is no data to be removed

Keyword 8: LIFO or FIFO

LIFO means last in first out. Whatever the last thing that was stored will be the first one out. As stated before stacks are LIFO

FIFO means first in first out. Whatever the first thing that was stored will be the first one out. Queues(which will be discusses later) are FIFO

Keyword 9: Queues(Array and linked list based)

A queue is a first in first out data structure. Where with a stack you could only add or remove from the top, with a queue you add to the top(or back, depending on if you like to envision a queue as a sideways stack) but you remove from the bottom(front).

  • In a stack you can push, pop and peek, in a queue you enqueue, dequeue, and peek
  • In an array based queue the last unused element of the array is where you will store new data and the first used element of the array is where you remove data
  • In a linked list based queue you append to the end of the list to store new data and delete the first node to remove data.

Keyword 10: Enqueuing

Enqueuing is a queues version of pushing. You simply add new data to the “end” of whatever type of queue you are using.

Keyword 11

Dequeuing is the process of removing the FIRST thing that was stored in your queue, unlike a stack where the last thing stored is removed.

Keyword 12:Overrun and Underrun conditions

Overrun(queue overflow) occurs when you try to add data onto a queue that is full Underrun(queue underflow occurs when you trying to remove data from a queue that is empty

hpc1 Topics

Keyword 1

Identification and definition of the chosen keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
    return(0);
}

Keyword 2

Identification and definition of the chosen keyword.

If you want to demonstrate something on the command-line, you can do so as follows:

lab46:~$ cd src
lab46:~/src$ gcc -o hello hello.c
lab46:~/src$ ./hello
Hello, World!
lab46:~/src$ 

Keyword 3

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
    return(0);
}

Keyword 4

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you want to demonstrate something on the command-line, you can do so as follows:

lab46:~$ cd src
lab46:~/src$ gcc -o hello hello.c
lab46:~/src$ ./hello
Hello, World!
lab46:~/src$ 

Keyword 5

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
    return(0);
}

Keyword 6

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you want to demonstrate something on the command-line, you can do so as follows:

lab46:~$ cd src
lab46:~/src$ gcc -o hello hello.c
lab46:~/src$ ./hello
Hello, World!
lab46:~/src$ 

Keyword 7

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
    return(0);
}

Keyword 8

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you want to demonstrate something on the command-line, you can do so as follows:

lab46:~$ cd src
lab46:~/src$ gcc -o hello hello.c
lab46:~/src$ ./hello
Hello, World!
lab46:~/src$ 

Keyword 9

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
    return(0);
}

Keyword 10

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you want to demonstrate something on the command-line, you can do so as follows:

lab46:~$ cd src
lab46:~/src$ gcc -o hello hello.c
lab46:~/src$ ./hello
Hello, World!
lab46:~/src$ 

Keyword 11

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
    return(0);
}

Keyword 12

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you want to demonstrate something on the command-line, you can do so as follows:

lab46:~$ cd src
lab46:~/src$ gcc -o hello hello.c
lab46:~/src$ ./hello
Hello, World!
lab46:~/src$ 

sysprog Topics

Keyword 1: Device files

Everything in unix is a file and that includes any device on the system. Depending on the device, device files can be written to and read from just like any other file. The monitor device file can be written to but not read from. A keyboard can be read from but not written to.

Keyword 2: Race condition

A race condition is when multiple processes are able to access shared data and they try to change it at the same time. It is called a race condition because the result is depending on the timing of events. page 149 of understanding unix/linux programming has a good example.

Keyword 3:Atomic operations

An atomic operation is when the kernel joins two or more system calls into one indivisible unit. Meaning the entire sequence of calls has to be performed or none at all. Page 150 of understanding unix/linux programming talks briefly about it.

Keyword 4: Streams

The STREAMS model of data flow and connection attributes allows for modularity of processing. You can write or remove modules as you see fit.

Keyword 5: Blocking vs. Non-Blocking

Blocking is when a call waits for input. If there is no input then the program waits for it. Non-Blocking is when when blocking is turned off thus if there is no input the program will still continue.

Keyword 6: Signals

A Signal can be defined as a one word message sent by the kernel. Each signal has a numerical code. Requests for signalcs can come from processes, exceptions and user keystrokes. Many signals cause processes to die, but there are other types of signals. You can typically find the list of signals in /usr/include/signal.h

Keyword 7: Event driven programming

  • Event driven programming is a type of programming in which the flow of the written programmed is determined by certain events. User interaction, responses from other programs etc.

Keyword 8: Alarms, interval timers

  • Alarm is a simple unix function that allows you to schedule an action in the future, thus allowing for an action to happen automatically. it has a resolution down to 1 second.
  • Interval timers is a system that was added to unix that has a higher resolution(down to microseconds) and has 3 seperate timers. The three timers are real which ticks in real time, virtual which only ticks when a process is being run in user mode, and prof which ticks when a process is running in user mode and when the kernel is running system calls made by said process.

Keyword 9: reentrant code, critical sections

  • Code that can be called when it's already running and not cause any problems is said to be reentrant.
  • Critical sections are sections of code that if interrupted can cause incomplete or damaged data.

Keyword 10: Asynchronous i/o

  • Asynchronous i/o allows for other processes to continue before the transmission is finished, it is non blocking i/o.

Keyword 11: Programs and Processes

  • A Program is a list of machine-language instructions. When a program runs the “list” is simply loaded into memory and the processor executes the instructions.
  • A Process is simply a program in action, more specifically it is the memory space and settings with which the program runs.

Keyword 12:Parent/Child processes

  • A Child process is a process that is created by the parent process, typically using fork(). When initially created it is virtually a copy of the parent process.

cprog Objective

Objective: structures vs. classes

What is the difference between a structure and a class?

  • A structure is used to bundle different data types together, and that is about all it can do. Its members(variables) are public by default. A class is an extended version of a structure used in c++ that is allowed to contain functions as well, basically its a structure that has executable code within it, something a struct cannot do. By default all the members of a class are private, another major difference between the two.

data Objective

Objective: data structs in memory

How are data structures allocated and used in memory?

Just like any variable type data structures are given a memory address. Data structures typically have nodes and each node has its own address, this is done in C with the malloc() function.

hpc1 Objective

Objective

State the course objective; define what that objective entails.

Method

State the method you will use for measuring successful academic/intellectual achievement of this objective.

Measurement

Follow your method and obtain a measurement. Document the results here.

Analysis

Reflect upon your results of the measurement to ascertain your achievement of the particular course objective.

  • How did you do?
  • Room for improvement?
  • Could the measurement process be enhanced to be more effective?
  • Do you think this enhancement would be efficient to employ?
  • Could the course objective be altered to be more applicable? How would you alter it?

sysprog Objective

Objective: signals

Design a program that handles signals.

#include <signal.h>
#include <stdio.h>
 
void intu();
void seg();
 
 
int main()
{
	char *array;
	signal(SIGINT, intu); //interrupt aka ctrl c
	signal(SIGSEGV, seg);// good ol seg fault why is it V instead of F?
	getchar();
	printf("%c\n", *array);// why does this continue to segment?
 
	return 0;
}
 
void intu()
{
	printf("You tried to interrupt me but I won't let you!\n");
}
 
void seg()
{
	printf("I segmented!\n");
 
}

Experiments

Experiment 1 Structure variables

Question

When defining a struct, can you give a value to any variables within the struct? If not, then why not?

Below is the code I attempted to compile:

#include <stdio.h>
 
 
 
struct list
{
	int variable = 57;
};
 
int main()
{
 
	/*struct list fashizzle;
	fashizzle.variable = 10;
	printf("\nThe variable is %d\n", fashizzle.variable);*/
 
	return 0;
}

Here is what happens when attempting to compile:

lab46:~/Desktop/experiments$ gcc -Wall structvar.c 
structvar.c:7: error: expected ':', ',', ';', '}' or '__attribute__' before '=' token
lab46:~/Desktop/experiments$ 

So the answer to the question is: No you cannot give value to a variable when defining a struct.

The reason for this is quite simple, as I have stated in previous parts of my opus a variable is simply a human name given to an address. When you are defining a structure, you are not assigning an address yet, that does not happen until you actually declare a structure in the main program. At that point a memory address is given and now you can give it a name and store a value.

Experiment 2 Enum 0 or 1

Question

After learning about enum I was curious as to what value it starts at, is it 0 or 1? Or possibly some other random value?

Here is my code:

#include <stdio.h>
 
int main()
{
	enum days{sunday, monday, tuesday, wednesday, thursday, friday, saturday};
	printf("%d\n", sunday);
	printf("%d\n", monday);
 
	return 0;
}

Here is the output:

lab46:~/Desktop/experiments$ ./a.out 
0
1
lab46:~/Desktop/experiments$

It would appear that the default for enum is to start at 0

Experiment 3: Enum + 1

I was curious if enumerated values would still allow you to math operators. Basically I am going to take an enumerated variable and see if I can add one and get the next enumerated variable.

Using the same code in previous experiment except instead of printing Monday, I will try to print sunday + 1

#include <stdio.h>
 
int main()
{
	enum days{sunday, monday, tuesday, wednesday, thursday, friday, saturday};
	printf("%d\n", sunday);
	printf("%d\n", sunday+1);
 
	return 0;
}

Here is the output:

lab46:~/Desktop/experiments$ ./a.out 
0
1
lab46:~/Desktop/experiments$ 

As we can see it worked the same way as the previous experiment meaning enumerated variables can still have math ops used on them.

Part 3

Entries

November 4, 2011

  • New month, new day, new headaches caused by feeling like I am behind in many classes. Data/system/cprog seem to be going well. Binary trees seem very simple and I am moderately confident I can make modifications to my doubly linked list libraries to get tree functionality. Discrete/data comm friggin suck anymore, and hpc I really need to get some direction from Matt. I feel like I have learned all the basics of C and will soon have to spend more time on C++, yay for me.

November 18, 2011

  • Time to do some more keywords, hopefully I an get these out of the way so I can focus on other things. Things are fine with data and sys prog but I have to do some work with hpc and figure out what the hell is going on with discrete and data comm.

November 21, 2011

Despite the fact that the class is watching troll 2 on the video wall I am going to attempt to actually do some work. One more keyword for sys prog then I must tackle data structs.

December 1, 2011

   The third part of opus is done and now it is time for eoce.  As usual I think I overreacted to the amount of work as the teacher seems to be very understanding and doesnt seem to expect everyone to get everything done.  I think he is just looking more for progress and a willingness to learn.  I can safely say that I have definitely made progress and learned a lot this semester.  Sometimes I got frustrated but just about every time I asked about a topic the teacher was able to lead me to learning something new.  I can also safely say I cannot wait for a break!

cprog Topics

Keyword 1: C library, libraries, makefile

  • libraries are predefined code and header files that store common functionality. The C standard library includes your basic i/o operations, string functions etc.
  • Makefiles is basically a script containing commands for the utility make. It allows for code compiling with predetermined arguments.

Keyword 2: Mult-file programs

  • Multi-File programming allows for several .c files to be compiled into one binary file. Only one of the files can have a defined function of a given name. Meaning you cant have main() in two different files. All files have to have same header. To compile all the files into one is no different than compiling a single file, except after typing gcc you type all the files names in the order that you want compiled. You can also write a makefile to automate the process.

Keyword 3: I/O stream

  • I/O stream is c++'s version of STD I/O and in fact is built off of STD I/O. Four key components of the i/o stream are cin, cout, cerr and stream operators.
  • cin Deals with input, reads in user input or possibly information file
  • cout Deals with output, prints requested information
  • cerr Specifically deals with error messages
  • Stream operators
    • Insertion operator(«) is used with cout. cout«1; means the value of one is “inserted” into cout(aka output) printed to screen.
    • extraction operator(») is used with cin. cout»variable; means the value entered by the user will be stored in variable.

Keyword 4: Array of char vs. C++ string data type

  • The C++ string data type has the same functionality as an array of chars in C. You can still access individual elements of the string by using the array index[] and there are built in string functions if needed. Concatenation, comparison etc.

Keyword 5: Namespaces

  • Namespaces allow you to group things together, like variables, classes, objects and functions.

here is a good resource for further understanding

Keyword 6: Templates

  • Templates allow for generic functions in c++ thus allowing for the same function to be used for multiple types without having to write the code again.

Keyword 7: Standard template library

  • The standard template library is a library that includes common templates classes.

Keyword 8: type casting operators

  • Casting is when you change the representation of a variable type. In C it is as simple as (char) int; which can also be done in c++ but c++ also has several additional operators as listed here

Keyword 9: constant/volatile

  • Const defines a variable as constant meaning it cannot be modified.
  • Volatile defines a variable as volatile meaning that it can be modified in some way not known by the compiler

Keyword 10: classes and objects

  • Classes are similar to structs in c but can have functions as well. Classes are specifically just a definition.
  • Objects are a declaration of a class.

Keyword 11: Access control

There are three levels of access control within a class:

  • Public members of a class are accessible by any function.
  • protected members are accessible to members of classes that inherit from the class in addition to the class itself and any friends.
    • friends are classes that are given permission to access protected data of another class
  • private are only accessible by functions of the class.

Keyword 12

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you want to demonstrate something on the command-line, you can do so as follows:

lab46:~$ cd src
lab46:~/src$ gcc -o hello hello.c
lab46:~/src$ ./hello
Hello, World!
lab46:~/src$ 

data Topics

Keyword 1: LIFO and FIFO

Keyword 2: Computational complexity

  • Computational complexity is the concept of classifying the difficulty of a computing program.

resource

Keyword 3:Big-O, theta, bounds

In computer science, Big-O and Big theta is used to describe how an algorithm responds to different input sizes. This can be used to describe an algorithm's efficiency by determining processing time and working space requirements. Depending on the bounds you wish to describe will determine which notation would be used as big-o is more for just having an upper bound where big theta is upper and lower.

Keyword 4: Sorting algorithms

  • Sorting algorithms are programs that sort elements of a list into a specified order.

Keyword 5: Selection sort

  • Selection sorting is a simple algorithm that finds the smallest value in a list and puts it in the first element, then moves to the next element and repeats until list is ordered.

resource

Keyword 6:Bubble sort

  • Bubble sorting algorithm is a sorting algorithm that starts at the first element of the list and compares it to the next element. If the first is greater than the second it swaps them, then moves to comparing the second and third elements, repeating and moving through the list. it repeats the process through the list until no swaps happen.

resource

Keyword 7: Insertion sort

  • Insertion sorting algorithms creates a new list of the same number of elements as the list to be sorted, and then sorts the list by copying the elements in specified order into the new list.

resource

Keyword 8: Quick sort

  • Quick sorting algorithms is an algorithm that picks a pivot point of a list then divides the list by that pivot point. One list will contain all values greater than the pivot point, and the other will contain all values less than the pivot. One list will also be chosen to store the pivot point. This process is repeated until the list is sorted.

resource

Keyword 9: Merge sort

  • Merge sort algorithms are similar to quick sorts in that they divide the list and merge it back together, it simply lacks a pivot point.

more

  • Binary Search is a simple search where you typical pick the middle of the list and compare if the searched value is less than, equal, or greater than chosen value. If the searched value is less than the picked value it will remove every element greater from the search and vice versa.

Keyword 11: Trees, Binary Trees(nodes, parents, children)

  • Trees are a type of data structure where each node can have children nodes. In a binary tree each node can have two child nodes. Typically the right node will be a value greater than the value in the parent node, and the left node will be a value less than the parent node.

Keyword 12: Searching a binary tree

  • Binary searching compares each parent branch as to whether is is greater than less than or equal to the searched value, if the element is not the value it effectively cuts half of the list out of the search. The process is run until the lowest level of the tree is searched of the value is found.

resource

hpc1 Topics

Keyword 1

Identification and definition of the chosen keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
    return(0);
}

Keyword 2

Identification and definition of the chosen keyword.

If you want to demonstrate something on the command-line, you can do so as follows:

lab46:~$ cd src
lab46:~/src$ gcc -o hello hello.c
lab46:~/src$ ./hello
Hello, World!
lab46:~/src$ 

Keyword 3

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
    return(0);
}

Keyword 4

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you want to demonstrate something on the command-line, you can do so as follows:

lab46:~$ cd src
lab46:~/src$ gcc -o hello hello.c
lab46:~/src$ ./hello
Hello, World!
lab46:~/src$ 

Keyword 5

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
    return(0);
}

Keyword 6

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you want to demonstrate something on the command-line, you can do so as follows:

lab46:~$ cd src
lab46:~/src$ gcc -o hello hello.c
lab46:~/src$ ./hello
Hello, World!
lab46:~/src$ 

Keyword 7

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
    return(0);
}

Keyword 8

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you want to demonstrate something on the command-line, you can do so as follows:

lab46:~$ cd src
lab46:~/src$ gcc -o hello hello.c
lab46:~/src$ ./hello
Hello, World!
lab46:~/src$ 

Keyword 9

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
    return(0);
}

Keyword 10

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you want to demonstrate something on the command-line, you can do so as follows:

lab46:~$ cd src
lab46:~/src$ gcc -o hello hello.c
lab46:~/src$ ./hello
Hello, World!
lab46:~/src$ 

Keyword 11

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

/*
 * Sample code block
 */
#include <stdio.h>
 
int main()
{
    return(0);
}

Keyword 12

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you want to demonstrate something on the command-line, you can do so as follows:

lab46:~$ cd src
lab46:~/src$ gcc -o hello hello.c
lab46:~/src$ ./hello
Hello, World!
lab46:~/src$ 

sysprog Topics

Keyword 1: i/o redirection

.

  • Redirection is a common to command line interpreters in unix that allow for for standard i/o to be redirected to specified locations.

Keyword 2: Pipes

  • Pipes are used with redirection, basically altering the command entered so it does something different than default

Keyword 3 Server/socket

  • A server accepts and processes requests from clients
  • A server requires a socket to access the network. A socket is an endpoint of communication allowing a network application to plug into the network. You typically only have one physical interface but many software sockets can use a single interface simultaneously.

Keyword: Client server model

  • In the client/server model the server accepts process requests placed by the client. The server sets up server sockets that have an address and able to receive connections. Clients create client sockets which do not care about their address. A server can either directly handle the request itself or fork to create a new process to handle the process.

Keyword 5: Coroutines

  • Coroutines are connected processes that work together to complete a function. The processes continue to run and control is passed from one to another as each completes a certain task.

Keyword 6: connections and protocols

  • A connection is when the client and server are linked allowing for data to be to be sent and received.
  • Protocols are the rules of communication between the client and server.

Keyword 7: Server socket

Keyword 8: client sockets

Keyword 9: Zombie

  • A zombie process or a defunct process is a process that has died bstull still has an uncollected exit value.

Keyword 10: Datagrams

  • Datagram communicaton isdoes not make a connection like sockets but instead simply sends a message to an address.

Keyword 11: Tcp vs. udp

  • Tcp aka transmission control protocol is used for non time critical applications
  • Udp aka User Datagram Protocol is used when timing is a little more critical

resource

Keyword 12: Distributed systems

  • A **distributed system* is a series of computers connected through a network but with the added benefit of being able to share all resources of the system.

resource

cprog Objective

Objective

State the course objective; define what that objective entails.

Method

State the method you will use for measuring successful academic/intellectual achievement of this objective.

Measurement

Follow your method and obtain a measurement. Document the results here.

Analysis

Reflect upon your results of the measurement to ascertain your achievement of the particular course objective.

  • How did you do?
  • Room for improvement?
  • Could the measurement process be enhanced to be more effective?
  • Do you think this enhancement would be efficient to employ?
  • Could the course objective be altered to be more applicable? How would you alter it?

data Objective

Objective

State the course objective; define what that objective entails.

Method

State the method you will use for measuring successful academic/intellectual achievement of this objective.

Measurement

Follow your method and obtain a measurement. Document the results here.

Analysis

Reflect upon your results of the measurement to ascertain your achievement of the particular course objective.

  • How did you do?
  • Room for improvement?
  • Could the measurement process be enhanced to be more effective?
  • Do you think this enhancement would be efficient to employ?
  • Could the course objective be altered to be more applicable? How would you alter it?

hpc1 Objective

Objective

State the course objective; define what that objective entails.

Method

State the method you will use for measuring successful academic/intellectual achievement of this objective.

Measurement

Follow your method and obtain a measurement. Document the results here.

Analysis

Reflect upon your results of the measurement to ascertain your achievement of the particular course objective.

  • How did you do?
  • Room for improvement?
  • Could the measurement process be enhanced to be more effective?
  • Do you think this enhancement would be efficient to employ?
  • Could the course objective be altered to be more applicable? How would you alter it?

sysprog Objective

Objective

State the course objective; define what that objective entails.

Method

State the method you will use for measuring successful academic/intellectual achievement of this objective.

Measurement

Follow your method and obtain a measurement. Document the results here.

Analysis

Reflect upon your results of the measurement to ascertain your achievement of the particular course objective.

  • How did you do?
  • Room for improvement?
  • Could the measurement process be enhanced to be more effective?
  • Do you think this enhancement would be efficient to employ?
  • Could the course objective be altered to be more applicable? How would you alter it?

Experiments

Experiment 1: NoTouchy!

Question

Can a child touch its parents private parts?

  • The code below will have a child class inherit private parts:
#include <iostream>
 
using namespace std;
 
class parent
{
	private:
		int number;
};
 
 
class child : private parent
{
 
	public:
		char character;
		void print();
};
 
int main()
{
	child notouchy;
	notouchy.number = 10;
	notouchy.print();
 
	return 0;
}
 
 
void child::print()
{
	cout<<number;
}
  • Here is what happens when you compile:
lairstation3:~/Desktop$ g++ privateparts.cc -Wall
privateparts.cc: In function ‘int main()’:
privateparts.cc:8: error: ‘int parent::number’ is private
privateparts.cc:23: error: within this context
privateparts.cc: In member function ‘void child::print()’:
privateparts.cc:8: error: ‘int parent::number’ is private
privateparts.cc:32: error: within this context
  • As you can see on line 8 you get an error that the variable is private.
  • Just to verify I am going to change from private to public and it will now work.
#include <iostream>
 
using namespace std;
 
class parent
{
	public:
		int number;
};
 
 
class child : public parent
{
 
	public:
		char character;
		void print();
};
 
int main()
{
	child notouchy;
	notouchy.number = 10;
	notouchy.print();
 
	return 0;
}
 
 
void child::print()
{
	cout<<number;
}
  • Here is what happens when I compile and run after changing from private to public:
lairstation3:~/Desktop$ g++ privateparts.cc -Wall
lairstation3:~/Desktop$ ./a.out
10
  • as you can see the code now compiled and runs, so a child class cannot touch its parents private parts.

Experiment 2: Private/Public default?

Question

When declaring variables within a class do they default to private or public?

  • I am going to use the same code I used for my notouchy experiment.
  • I am simply going to remove any reference to public or private and see what happens!
#include <iostream>
 
using namespace std;
 
class parent
{
 
		int number;
};
 
 
class child : parent
{
 
 
		char character;
		void print();
};
 
int main()
{
	child notouchy;
	notouchy.number = 10;
	notouchy.print();
 
	return 0;
}
 
 
void child::print()
{
	cout<<number;
}
  • Here is what happens when you compile:
lairstation3:~/Desktop$ g++ privateparts.cc -Wall
privateparts.cc: In function ‘int main()’:
privateparts.cc:8: error: ‘int parent::number’ is private
privateparts.cc:23: error: within this context
privateparts.cc:17: error: ‘void child::print()’ is private
privateparts.cc:24: error: within this context
privateparts.cc: In member function ‘void child::print()’:
privateparts.cc:8: error: ‘int parent::number’ is private
privateparts.cc:32: error: within this context
lairstation3:~/Desktop$ 
  • As you can see by the error's the default for classes is private!

Experiment 3: Does inheritance from parent to child default to public parts?

  • Typically when declaring a child class you use put “public” in front of the parent class. Being that a child can only inherit the public parts of a parent class, I want to test what will happen if you do not put public in front of parent.
#include <iostream>
 
using namespace std;
 
class parent
{
	Public:
		int number;
};
 
 
class child : parent
{
 
	Public:
		char character;
		void print();
};
 
int main()
{
	child notouchy;
	notouchy.number = 10;
	notouchy.print();
 
	return 0;
}
 
 
void child::print()
{
	cout<<number;
}
  • Weird things happen when compiling:
lairstation3:~/Desktop$ g++ privateparts.cc -Wall
privateparts.cc: In function ‘int main()’:
privateparts.cc:8: error: ‘int parent::number’ is inaccessible
privateparts.cc:23: error: within this context
lairstation3:~/Desktop$ 
  • I was really not expecting this and couldn't figure it out at first, then I tried putting private in front of parent on line 12
#include <iostream>

using namespace std;

class parent
{
	public:
		int number;
};


class child : private parent
{

	public:
		char character;
		void print();
};

int main()
{
	child notouchy;
	notouchy.number = 10;
	notouchy.print();

	return 0;
}


void child::print()
{
	cout<<number;
}
  • Here is the compilation errors again:
privateparts.cc: In function ‘int main()’:
privateparts.cc:8: error: ‘int parent::number’ is inaccessible
privateparts.cc:23: error: within this context
lairstation3:~/Desktop$ 
  • So it turns out that the default is once again private!
opus/fall2011/kkrauss1/start.txt · Last modified: 2014/01/19 09:20 by 127.0.0.1