User Tools

Site Tools


opus:spring2012:rmatsch:start

Robert spring 2012 Opus

(MODIFY OR REMOVE) OPTIONAL SUBTITLE

Introduction

Hi my name is Robert i enjoy the outdoors very much. My future plans are to further my education at RIT and obtain a bachelors degree in software engineering.

Part 1

Entries

Entry 1: January 25, 2012

On january 25 I experienced compressing and uncompressing files using gzip and gunzip. Gzip and gunzip are utilities you can use to allow for easy compressing of files and extracting of files. First gzip is used for compressing files. This utility works by opening up a command prompt and typing gzip(space)filesname.txt then press enter. This just compressed your file. To check to see if it is compressed type ls command on a command prompt and you will see filename.txt.“gz” meaning it was compressed with gzip utility. Now to unzip the compressed file type gunzip filename.txt and it will uncompressed to the current directory you are in. To check this issue ls command and see that your file does not have .gz after it. This is one way of easy compression and extracting files which is very useful utility to know.

Entry 2: January 26, 2012

chmod is a utility that allows you to change permissions on a file. My reason for writing about this utility is because changing permissions via the symbolic way is messy. When using chmod to change the permission you first need to understand a few things. First there are different permissions and they are: User (u) the user that owns the file, group (g) which is the group that owns the file and then other (o) which is everyone else on the system. Each of these has the read ® write (w) and execute/search(x) permission attached to each. An example would be rwxr-xr-x to rmatsch the answer.txt file. The first three letters correspond to the permission of the owner of the file then the next three are the permissions for group and then three more for other. Notice how there is a dash where a letter would be. This is because that particular group, owner,or other does not have that privilege. Also access to rwx for owner means access of (7). r-x means group access (5) and –x means other has access (1). This calculation is done by attributing the value 4 for read, 2 for write, and 1 for execute/search. If you add rwx you get (7). I should also mention the reason for 0-7 is because this is assigning of permissions by octal. For example, to assign read/ write/ execute permission for owner, read/execute for group and execute for other or commonly known as the “world” you would type in at the command prompt chmod 751 the answer.txt which would change the permission to the example listed above. The significant using octal for changing permission of files is because it takes longer changing files via symbolic notation, saving time and in the business world money. Changing permission via symbolic example: “Chmod o+rwx filename.txt” just sets other(o) to full permission read write and execute. A simple command such as “chmod 644 filename.txt” sets all three very quickly and less error is likly while typing.

Entry 3: Febuary 15, 2012

            root
              |
            home
              |
           rmatsch
              |
   ___________________________
  |      |      |      |      |
 bin    src   file.c    lab2  hello.c
         |
     __________
    |    |     |
 cprog  unix   submit
    |
    |____________________
    |          |         |
Contact.info   var2.c   array.c

Entry 4: Febuary 17, 2012

To access unconventional names there is three basic things to remember. When looking up files named unconventionally is not very fun thankfully you can use three characters to help with this. the characters are *,\, and ” ”. if given the file *?? ghty.file normal cat utility would when run on this would cat *?? And then cat ghty.file separately but if you were to type cat *??* you would be able to access the content. Another way use the \ to escape the following character so you would type cat *??\(space)ghty.file and then hit enter. Finally another quick and easy way is to use ” ”. This looks like this cat “*?? ghty.file” and then you can access the content.

* \ ” ” or ' '

Keywords

Cprog Keywords

Standard I/O (STDIO, STDOUT, STDERR)

■ Header Files (Local and System), C Standard Library (Libc), Libraries……X

■ arithmetic (equations, operators)…..X

■ logic and operators (and, or, not, xor)

■ Variables (types, ranges, sizes)…..X

■ Scope (Block, Local, Global, File)

■ Pointers (address of, assignment, dereferencing)…..X

■ Type Casting

■ Selection Structures (if, case/switch)……X

■ Repetition/Iteration Structures (for, while, do while)….X

■ Arrays (standard notation, pointer arithmetic, single-dimensional, multi-dimensional)…..X

■ File Access (Read, Write, Append)…..X

■ Structures (Declaration, Accessing Elements, Pointers to)

■ typedef, enum, union

■ Functions, Parameters (Pass by: Value, Address, Reference), Return Types, Recursion, Command-line arguments

■ Compiler, Preprocessor, Flags, Assembler, Linker, Multi-file programs (how to structure, how to compile)

■ I/O Streams (cin, cout, cerr, stream operators) [C++]

■ Namespaces [C++]

■ Type Casting Operators, Const-Volatility Specifiers (const, volatile) [C++]

■ Classes (Objects, Constructor, Destructor, Access Control, Public, Protected, Private, Friend, “this” pointer) [C++]

■ Inheritance (single, multiple Inheritance), Polymorphism/Virtual Functions, Abstract Base Class [C++]

■ Overloading (Functions, Operators) [C++]

■ Exception Handing (throw, try, catch) [C++]

■ Templates, STL (Standard Template Library) [C++]

Variables

Definition

Variables are storage containers which can be permanent but most of the time they vary or change throught a computer program.

Demonstration

Variables have 3 basic properties.First is name, in order to use a variable you must have declare a name for the variable to call it by. secondly you must select a data type such as type “interger” or “char”. Thirdly is the size of this container you want the variable to be. Thankfully this is already determined by the data type you have established so the work is already done. The data type selected can hold a certain amount of data. Below is code for a program to show you the different sizes of a data types there ranges the unique values they can have.I must also mention that upon selection of a data type there are signed and unsigned variables also. Signed variables can handle negative along with positive values and unsigned variables can handle only positive values.

Code :

#include <stdio.h>
#include <math.h>
int main()
{
        // declare variables
        unsigned char uc = 0;
        signed char sc = 0;
        signed short int ssi = 0;
        unsigned short int usi =0;
        signed long int sli = 0;
        unsigned long int uli =0;
        signed long long int slli = 0;
        unsigned long long int ulli = 0;
        signed int si  = 0;
        unsigned int ui = 0;
        unsigned long long int quantity = 0;
 
        //display info for unsigned char data type
        printf("Unsigned char is %u bytes\n", sizeof(uc));
        printf("The range of an unsigned char is %hhu to %hhu\n", uc, (uc-1));
        quantity=(unsigned char)(uc-1) + 1;/* unsigned char -1 = 255 +1 for all unique values*/
         printf("An unsigned char can store %llu unique values\n\n", quantity);
        //display info for signed char data type
        printf("Signed char is %d bytes\n", sizeof(sc));
        quantity = (unsigned long long int)pow(2, (sizeof(sc)*8)); /*2 raised to the power of 8 times data type in  bytes */
        printf("The range of a signed char is %hhd to %hhd\n", (sc-(quantity/2)), (sc+(quantity/2)-1));
         printf("A unsigned char can store %llu unique values\n\n", quantity);
 
        printf("Unsigned short int is %u bytes\n", sizeof(usi));
        quantity = (unsigned long long int)pow(2, (sizeof(usi)*8));
         printf("The range of a unsigned short int is %u to %llu\n", usi, ((quantity)-1));
         printf("An unsigned short int can store %llu unique values\n\n", quantity);
 
        printf("Signed short int is %d bytes\n", sizeof(ssi));
        quantity = (unsigned long long int)pow(2, (sizeof(ssi)*8));
       printf("The range of a signed short int is %lld to %lld\n", (ssi-(quantity/2)), (ssi+(quantity/2)-1));
        printf("A signed short int can store %llu unique values\n\n", quantity);
 
 printf("Signed int is %d bytes\n", sizeof(si));
        quantity = (unsigned long long int)pow(2, (sizeof(si)*8));
         printf("The range of a signed int is %lld to %lld\n", (si-(quantity/2)), (si+(quantity/2)-1));
        printf("A signed int can store %llu unique values\n\n", quantity);
 
        printf("Unsigned int is %u bytes\n", sizeof(ui));
        quantity = (unsigned long long int)pow(2, (sizeof(ui)*8));
         printf("The range of a unsigned int is %llu to %llu\n", ui,((quantity)-1));
        printf("An unsigned int can store %llu unique values\n\n", quantity);
 
        printf("Signed long int is %d bytes\n", sizeof(sli));
        quantity = (unsigned long long int)pow(2, (sizeof(sli)*8));
         printf("The range of a signed long int is %lld to %lld\n", (sli-(quantity/2)), (sli+(quantity/2)-1));
        printf("A signed long int can store %llu unique values\n\n", quantity);
 
        printf("Unsigned long int is %u bytes\n", sizeof(uli));
        quantity = (unsigned long long int)pow(2, (sizeof(uli)*8));
         printf("The range of a unsigned long long int is %llu to %llu\n", uli,((quantity)-1));
        printf("An unsigned long int can store %llu unique values\n\n", quantity);
 
 
         printf("Signed long long int is %d bytes\n", sizeof(slli));
        quantity = (unsigned long long int)pow(2, (sizeof(slli)*8));
        printf("The range of a signed long long int is %lld to %lld\n", (slli-(quantity/2)), (slli+(quantity/2)-1));
        printf("A signed long long int can store %llu unique values\n\n", quantity);
 
        printf("Unsigned long long int is %u bytes\n", sizeof(ulli));
        quantity = (unsigned long long int)pow(2, (sizeof(ulli)*8));
         printf("The range of a unsigned long long int is %llu to %llu\n", ulli,((quantity)-1));
        printf("An unsigned long long int can store %llu unique values\n\n", quantity);
 
 
return(0);
}

What command line looks like when program is run.

lab46:~/src/cprog$ ./project0
Unsigned char is 1 bytes
The range of an unsigned char is 0 to 255
An unsigned char can store 256 unique values

Signed char is 1 bytes
The range of a signed char is -128 to 127
A unsigned char can store 256 unique values

Unsigned short int is 2 bytes
The range of a unsigned short int is 0 to 65535
An unsigned short int can store 65536 unique values

Signed short int is 2 bytes
The range of a signed short int is -32768 to 32767
A signed short int can store 65536 unique values

Signed int is 4 bytes
The range of a signed int is -2147483648 to 2147483647
A signed int can store 4294967296 unique values

Unsigned int is 4 bytes
The range of a unsigned int is 0 to 4294967295
An unsigned int can store 4294967296 unique values

Signed long int is 8 bytes
The range of a signed long int is -9223372036854775807 to 9223372036854775806
A signed long int can store 18446744073709551615 unique values

Unsigned long int is 8 bytes
The range of a unsigned long long int is 0 to 18446744073709551614
An unsigned long int can store 18446744073709551615 unique values

Signed long long int is 8 bytes
The range of a signed long long int is -9223372036854775807 to 9223372036854775806
A signed long long int can store 18446744073709551615 unique values

Unsigned long long int is 8 bytes
The range of a unsigned long long int is 0 to 18446744073709551614
An unsigned long long int can store 18446744073709551615 unique values

Pointers

Definition

variables are seen as memory cells that can be accessed using their identifiers (aka pointers). Because we did not have to care about the physical location of our data within memory, we can simply used its identifier when we need to refer to the variable.

Demonstration

Below is code to help understand what pointers acually do.

#include <stdio.h>
int main()
{
        // a is initiallly set to zero
        int a = 0;
        int * b; /* b is declared as a pointer variable by star b */
        b = &a; /* b is assigned the adress of a */
        *b = 12; /* what ever b is pointing at is now set equal to 12 not b itself */
 
        printf("a contains %u \n", a );
 
        printf("a's address is 0x%x\n", &a );
 
        printf("b contains %u \n", *b);
      // b contains the value stored at what b is pointing to. (the container or another variable)
        printf("b points to 0x%x\n", b);
 
        printf("b's addres is 0x%x\n", &b);
 
        return(0);
}
lab46:~/src/cprog$ ./var2
a contains 12
a's address is 0xe5a3f33c
b contains 12
b points to 0xe5a3f33c
b's addres is 0xe5a3f330

arithmetic

Definition
+ Adding binary operator, adds two operands to get a sum, (addend +adend = sum
- Subtract binary operator, inverse of adding, (minuend -subtrahend = difference)
% Modulus takesremainder after an integer division
++ means +1
-- means -1
* Multiply binary operator (multiplicand times multiplier = product)
/ Divide binary operator(dividen / divisior = quotient)
Demonstration
c=5
b=3
p=5
q=5

c-b=a = 5-3=2 a =2 
c+b=a = 5+3=8 a =8
c*b=a = 5*3=15 a =15
x=p/q = 5/5=1 a =1

c++ means c= to 5 plus one =6

cprog Keyword 4

Header files

Definition

Header Files are files that are incoporated in c code to allow you added funtionality such as use of funtions or expressions.

Demonstration

#include <stdio.h> #include <stdlib.h> code to demonstrate

#include <stdlib.h>
#include <stdio.h>
 
int main()
{
    return(0);
}

cprog Keyword 5

Arrays

Definition

Arrays can be thought of as sequentialy ordered containers. The ability to take a big piece of data such as string and break it up into individual pieces to be manipulted as needed. because arrays store data in “numbered containers” arrays are a good thing to know.

Demonstration
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
        unsigned char i;
 
        if (argc<2)
        {
                printf("%8s must be run with 1 or \
        more arguments, you only provide %hhu\n", *(argv+0),(argc-1));
                exit(1);
        }
        printf("pleas enter a message to be ciphered")
         for(i=0;i<argc; i++)
        {
                printf("argv[%hhu]: %s \n",i,*(argv+i));
        }
        return(0);
}
./acs h e y t h i s i s a n a r r a y
you ran this program with 17 arguments, they are:
argv[0]: ./acs
argv[1]: h
argv[2]: e
argv[3]: y
argv[4]: t
argv[5]: h
argv[6]: i
argv[7]: s
argv[8]: i
argv[9]: s
argv[10]: a
argv[11]: n
argv[12]: a
argv[13]: r
argv[14]: r
argv[15]: a
argv[16]: y

multidemensional array would look similar to this

   0 1 2 3
0  y r e d
1  a b h o 
2  f k z p 
3  t u m l

argv[1][2]:k

cprog Keyword 6

Selection Structures (if, case/switch)

Definition

selection structure is a order of sequence of check statments (conditional statements) that are true or false. If the stament is true then do somthing.

Demonstration
 if (in == NULL){
                fputs("please enter a message to cipher:\n", stdout);
                fgets(msg, sizeof msg, stdin);
                fprintf(nf, "%s", msg);
                fclose(nf);
                nf = fopen("nofile.txt", "r");
                letter1 = fscanf(nf,"%c", &letter);
        }else{
                 letter1 = fscanf(in, "%c", &letter);
 
        }if (key == NULL){
                printf("please enter a key to encipher with :\n");
                scanf("%d", &keyvalue);
        }else{
                fscanf(key,"%d",&keyvalue);

cprog Keyword 7

Repetition/Iteration Structures (for, while, do while)

Definition

Repetitive/iteration structures or loops are a statement which allows code to be repeatedly executed until a condition is meet or can be instructed to “do” something while this condition is true.

Demonstration
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
        unsigned char i;
 
        if (argc<2)
        {
                printf("%8s must be run with 1 or \
        more arguments, you only provide %hhu\n", *(argv+0),(argc-1));
                exit(1);
        }
        printf("you ran this program with %hhu arguments, they are:\n", argc);
         for(i=0;i<argc; i++)/* Condition to be checked */
        {
                printf("argv[%hhu]: %s \n",i,*(argv+i));
        }
        return(0);
}

another example

 while (letter1 != EOF)
        {
                if((letter >= 'A') && (letter <= 'Z'))
                        letter = (((abs(letter - 65) + keyvalue)%26)+65);
                else if((letter >= 'a') && (letter <= 'z'))
                        letter = (((abs(letter - 97) + keyvalue)%26)+97);

                fprintf(out,"%c",letter);
                if (in == NULL){
                        letter1 = fscanf(nf, "%c", &letter);
                }else{
                        letter1 = fscanf(in, "%c", &letter);
                }

cprog Keyword 8

File access

Definition

File Access is when you read from, write to, or append to a file. the program can read write or append to a file.

Demonstration

Demonstration 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:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
 
int main(){
        char letter1=0;
        char msg[250];
        FILE *in, *out, *key,*nf;
        char letter = 0;
        int keyvalue;
 
        nf = fopen("nofile.txt", "w");
        in = fopen("message.txt", "r");
        out = fopen("cipher.txt", "w");
        key = fopen("key.txt","r");
 
        if (in == NULL){
                fputs("please enter a message to cipher:\n", stdout);
                fgets(msg, sizeof msg, stdin);
                fprintf(nf, "%s", msg);
                fclose(nf);
                nf = fopen("nofile.txt", "r");
                letter1 = fscanf(nf,"%c", &letter);
        }else{
                 letter1 = fscanf(in, "%c", &letter);
 
        }if (key == NULL){
                printf("please enter a key to encipher with :\n");
                scanf("%d", &keyvalue);
        }else{
                fscanf(key,"%d",&keyvalue);
        }
        while (letter1 != EOF)
        {
                if((letter >= 'A') && (letter <= 'Z'))
                        letter = (((abs(letter - 65) + keyvalue)%26)+65);
                else if((letter >= 'a') && (letter <= 'z'))
                        letter = (((abs(letter - 97) + keyvalue)%26)+97);
  fprintf(out,"%c",letter);
                if (in == NULL){
                        letter1 = fscanf(nf, "%c", &letter);
                }else{
                        letter1 = fscanf(in, "%c", &letter);
                }
 
        }if (in == NULL){
                fclose(nf);
        }else{
                fclose(in);
        }
        if (key != NULL){
                fclose(key);
        }
 
 
        //fclose(in)
        fclose(out);
        //fclose(nf);
        return(0);
}
lab46:~/src/cprog$ cat cipher.txt
jpa
lab46:~/src/cprog$

lab46:~/src/cprog$ cat plain.txt
hey
lab46:~/src/cprog$

cprog Objective

cprog Objective

The course objective is for students to be able to write, compile code, use pointers and variables effectively and efficiently. Also this course is designed for students to gain a basic comprehension of memory such as various data types. Also obtain valuable debugging skills and demonstrate the ability to use logic and structure to solve problems. Develop solutions shown in c++ program language.

Method

To measure successful academic/intellectual achievement of this objective. students should be given a final project that incorporates various lessons learned through the course because an important part of intellectual achievement is applying what you leaned. Students should also be asked to write various programs on the spot and should be completed given sufficient time.

Measurement

Correctness - are things displayed when they are supposed to, were variables initialized etc. Design/efficiency- there is many ways to design a program but there may be better ways or more efficient ways. (Are the right size variables used?)

Logic- has a basic concept of logic (uses loop instead of 100 if statements) Other- Does the program do what it was designed to do and accurately.

Analysis

Reflecting upon my results of the measurement to ascertain achievement of the course objective.

* How did you do? I did not do to bad but still have a lot to learn. * Is there room for improvement?yes * Could the measurement process be enhanced to be more effective? Yes * Do you think this enhancement would be efficient to employ? Yes * Could the course objective be altered to be more applicable? No

Reflecting on the measurements I did not do too bad, but of course have a lot to learn so there is much room for improvement.

unix Keywords

Local host….X

■ Remote host……X

■ Home directory……X

■ Current working directory…..X

■ Types of files (regular, directory, special)……X

■ File manipulation…..X

■ Text Processing…..X

■ The VI editor…..X

unix Keyword 1

Local host

Definition

Local host is is the standard hostname given to the address of the loopback network interface or the web address of the computer you are working on. Although local host can take different forms, the web address is simply your computer's identifier.

Demonstration

enter “http://127.0.0.1” into any web browser, and you will see a web page hosted by a web server on the same computer if one is running.

unix Keyword 2

Remote host

Definition

Remote hosts are computers that are not locally accessed. They are further away from where you are such as servers or public internet.

Demonstration

a computer connected to lab46.corning-cc.edu through ssh is an example of a remote host

unix Keyword 3

File Manipulation

Definition

file manipulation is the ability to control files such as moving them, removing them, copying them.

Demonstration
lab46:~/src/cprog
lab46:~/src/cprog$ touch file123
lab46:~/src/cprog$ cp file123 file2
lab46:~/src/cprog$ rm file123
rm: remove regular empty file `file123'? y
lab46:~/src/cprog$ mkdir file123
lab46:~/src/cprog$ rmdir file123
lab46:~/src/cprog$ mv file2 /tmp
lab46:~/src/cprog$
lab46:~/src/cprog$ cd /tmp
lab46:/tmp$ ls
A.txt                        cformansencryption.c  fishd.log.vcordes1     img--01315.htm  img--93112.asc        lost+found   nofile.txt  prog1x5
aptitude-rlott.11795:dKeQWo  fbarb.txt             fishd.socket.vcordes1  img--12835.htm  img-file-88471.c      mc-jbamper   plain.txt   prog1x5.c
aptitude-rlott.11860:1ABldB  file2                 hsperfdata_brobbin4    img--39027.htm  img-logout-04391.asc  mc-tedmist1  prog1x4.c   wierdfileiswierd
lab46:/tmp$

unix Keyword 4

Home directory

Definition

The home directory is your default directory. Whenever you open up a cmd prompt you are at your home directory.

Demonstration
        root
              |
            home
              |
           rmatsch
              |
   ___________________________
  |      |      |      |      |
 bin    src   file.c    lab2  hello.c
         |
     __________
    |    |     |
 cprog  unix   submit
    |
    |____________________
    |          |         |
Contact.info   var2.c   array.c
 login as: rmatsch
rmatsch@lab46.corning-cc.edu's password:
 __         _     _ _   __   . . . . . . . . . . . . . . . . . . . . . . . . .
|  |   __ _| |__ / | |_/ /   . Basic System Usage:  Type 'usage' at prompt   .
|  |__/ _` | '_ \\_  _/ _ \  . Events and News:     Type 'news' at prompt    .
|_____\__,_|_.__/  |_|\___/  . Broken E-mail?       Type 'fixmail' at prompt .
---------------------------  . Check Lab46 Mail:    Type 'alpine' at prompt  .
c o r n i n g - c c . e d u  . . . . . . . . . . . . . . . . . . . . . . . . .

 Lab46 is the Computer & Information Science Department's Student Development
 Server for Computer-related coursework, projects, and exploration.  For more
 information, please check out:
  .. .  .    .        .                .                .        .    .  . ..
 .  Lab46 Web Page:       http://lab46.corning-cc.edu/                       .
 .  Lab46 Help Form:      http://lab46.corning-cc.edu/help_request           .
 .  Help E-mail:          haas@corning-cc.edu or wedge@lab46.corning-cc.edu  .
  .. .  .    .        .                .                .        .    .  . ..
You have old mail.
Last login: Sat Mar  3 09:06:57 2012 from user-10bj433.cable.mindspring.com
lab46:~$

by typing pwd you are shown where you are at in relaton to directories. Also by typing in cd you are defaulted back to your home directory even if you are in another directory.

lab46:~$
lab46:~$ pwd
/home/rmatsch
lab46:~$ cd src
lab46:~/src$ cd
lab46:~$

unix Keyword 5

Current working directory

Definition

The current working directory is the directory that you're in.

Demonstration

The current working directory is the directory that you are in. Typing cd command with no arguments will change your current working directory to your home directory.The pwd command reveals the current working directory.

lab46:~$ cd src/unix
lab46:~/src/unix$ pwd
/home/rmatsch/src/unix
lab46:~/src/unix$ cd
lab46:~$ pwd
/home/rmatsch
lab46:~$

unix Keyword 6

Text Processing

Definition

Text Processing is a tool used to edit text, save text into files or from files but can also be used to change it other text files.

Demonstration

“nano” is a good example of a text processing.

lab46:~$
lab46:~$ nano hello.c
#include<stdio.h>

int main()
{
        printf("Hello, World !\n");
        return(0);
}

unix Keyword 7

Types of files (regular, directory, special)

Definition

There are three basic types of files, regular files like text, directories such as a file that contains other files within, and special files which can be programs.

Demonstration

hello1.c is a txt file,unix is a directory that contains other files,and hello1 is a compiled c code program.

lab46:~/src$ ls
Makefile  cprog  hello1  hello1.c  submit  unix
lab46:~/src$
lab46:~/src$ cd unix
lab46:~/src/unix$
lab46:~/src/unix$ ls
arc.tar.gz    cs1.txt  cs3.txt  cs5.txt   lab1.txt  lab3.txt  lab5.txt
contact.info  cs2.txt  cs4.txt  lab0.txt  lab2.txt  lab4.txt  shell
lab46:~/src/unix$

unix Keyword 8

Vi editor

Definition

The VI editor is a text editor with two modes one mode you can only insert, and in another mode you can only enter commands.

Demonstration

Demonstration of the chosen keyword.

lab46:~$ vim hello.c
#include<stdio.h>

int main()
{
        printf("Hello, World !\n");
        return(0);
}
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"hello.c" 7L, 76C  

to write to this file i must hit the i key for insert and then insert is diplayed to show you what mode you're in.

~
-- INSERT --  

to save changes go to command mode by hitting esc key and then typing :wq to quit without saving type :q!

unix Objective

unix Objective

Upon completion of this course, students should be able to show:

familiarity with the structure of UNIX systems the ability to accomplish/automate tasks exposure to command-line tools and utilities experience the connection between UNIX and C understanding of the UNIX philosophy exposure to Open Source concepts and ideals familiarity with important system concepts exposure to computer security understanding and use of pattern matching problem solving activities

Definition

The objective entails being familiar and comfortable in using unix to accomplish task. It also entails understanding basic understandings of unix.

Method

The method i use for measuring successful academic/intellectual achievement of this objective would be to be asked to complete various task to be completted in a timly mannor for a final.

Measurement

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

Analysis

upon reflect my achievement of the particular course objective. i would do pretty good. Although i do pretty well there still could be room for improvement but am happy with the results.The measurement process could be enhanced to be more effective if more task were asked.I also believe these enhancement would be efficient to employ.however, what is asked for the objective is fine.

Experiments

Experiment 1

Question

What happens when you initialize a variable before the loop instead of initializing within the loop condition?

Resources

When using a loop in a program you have a condition that must be checked for the loop to start and end the loop. Usually the loop counting variable is initialized in the check condition of the loop.(common programming practice of loops)

Hypothesis

Before actually performing the experiment I believe that it will make no difference in how the program runs as long as the variable is not used before it is needed. Declaring global variables in a program are so you can use those variables throughout and at any part in the program so this includes the loop.

Experiment

I am going to test my hypothesis by developing a program which has a loop counting variable except i will initialize the variable in the start of the program instead of within the loop condition. My experiment will begin by first making a small program with initialization done within the loop condition. Then testing to make sure the program works and there are no bugs. Then I can proceed to initialize before the loop and not initialize with in the loop to see what happens.

Data

#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) 
{
        unsigned char i;
        i=0;
        if (argc<2)
        {
                printf("%8s must be run with 1 or \
        more arguments, you only provide %hhu\n", *(argv+0),(argc-1));
                exit(1);
        }
        printf("you ran this program with %hhu arguments, they are:\n", argc);
        for(i<argc; i++)
        {
                printf("argv[%hhu]: %s \n",i,*(argv+i));
        }
        return(0);
}

Analysis======Conclusions

The out come of this exsperiment for the above code did not work out. Upon analysis of why i looked closer at the loop condition parameters.The loop condition wants three parameters. this is known because when you go to **manuel for the “for loop” or type “man 3 for” in command line and get this 'For' loop

“SYNOPSIS

     for start test next body

_

DESCRIPTION

     For  is  a  looping  command,  similar in structure to the C for statement.  The start, next, and body arguments must be Tcl command strings, and test is an
     expression string.  The for command first invokes the Tcl interpreter to execute start.  Then it repeatedly evaluates test as an expression; if  the  result
     is non-zero it invokes the Tcl interpreter on body, then invokes the Tcl interpreter on next, then repeats the loop.  The command terminates when test eval-
     uates to 0.  If a continue command is invoked within body then any remaining commands in   the current execution of body are skipped; processing continues  by
     invoking  the Tcl interpreter on next, then evaluating test, and so on.  If a break command is invoked within body or next, then the for command will return
     immediately.  The operation of break and continue are similar to the corresponding statements in C.  For returns an empty string."

A loop condition will not look anywhere else in the program for the variables it needs. The loop expects the initialization to be done within the loop condition.(Example)for(i=0;i<argc; i++). The loop counter will not add outside of the loop and pull the info back to check it expects the variable to be initialized within the parentheses.so by my experiment i have proved my hypothesis to be incorrect and there was more involved then initially thought.

Experiment 2

Question

What will happend when i change *4 to *3 when allocating sizeof char when dealing with arrays.

Resources

class notes.

Hypothesis

Based on what you've read with respect to my original posed question, i believe that in a program that is dependant on atleast 4 memory spaces when changed to 3 will cause a segmentation fault or possible incorrect results.my rayional for this is because when there is not eough space it will usually truncate but to low of memory i believ it will seg fault.

Experiment

by running a program that depends on space for array and taking space out to see what will come of the program.

Data

The prgram compiled but when running it segmentation faulted.

Analysis

Based on the data collected:

  • Was your hypothesis correct? yes based on the data collected i was correct.
  • Was your hypothesis not applicable?no my hypothesis was applicable.
  • Is there more going on than you originally thought? No there was not more going on then when i thought.

Conclusions

What can you based on the experiment i can ascertain that by running a program with less memory then required will cause a segmentation fault.

Experiment 3

Question

What will happen if i use single quotes in a prinf funtion?

Resources

C ansi book

Hypothesis

I believe you will obtain an err message when tyring to compile. the reason for my educated guess is because printf() usually prints whats is in double quotes.

Experiment

my exsperiment will entail creating a program that prints a mesage to stdout with quotes and then without quotes

Data

#include<stdio.h>

int main()
{
        printf("Hello, World !\n");
        return(0);
}

and the other code to run is:

#include<stdio.h>
int main()
{
        printf('Hello, World !\n');
        return(0);
}
lab46:~$ gcc -o hello hello.c
hello.c:5:16: warning: character constant too long for its type
hello.c: In function 'main':
hello.c:5: warning: passing argument 1 of 'printf' makes pointer from integer without a cast
/usr/include/stdio.h:339: note: expected 'const char * __restrict__' but argument is of type 'int'
lab46:~$

Analysis

Based on the data collected the code did compile so i was wrong but when running the program it segmentation faulted.

Conclusions

I was suprised it compiled at first but when giving the exsperiment more time to think i the reason for warning is because it was taking hello, world! and putting it into string so that explains warnings and segmentation fault.

Part 2

Entries

Entry 5: March Day, 2012

For the UNIX course I currently enrolled in i have created a IRC bot phenny.It's pretty cool, once you get going it becomes alot of fun. Creating a phenny bot is significant because it allows you to script a bot and based on some conditions the bot does things.In the begining i had some difficulty with scripting but this activity helped me.

Entry 6: March Day, 2012

GNU debugger when you compile code use -g along with regular compile which looks like this gcc -g -o acs2 acs2.c

then run your program in the debugger:

gdb ./acs2 to fully use this debugger set breaking points such as break main break 11 break 17 once breaking points are set then you can run the program by typing “run” type “n” for next line you can also print values of variables if you type print “the variable name”

this is a very useful tool for finding possible mistakes or to fix mistakes. this is a very basic use of gnu debugger this debugger is capible of much more so please explore.

Entry 7: March Day, 2012

C++ OOP-Object-Oriented Programming to make a C++ file type .cc after you file instead of .c compile with g++ -o hello1 hello.cc

C++ class notes Classes & Objects Inheritance/Multiple Inheritance Polymorphism Templates

Entry 8: March Day, 2012

class notes on struct

struct person{
        char *name;//or --char name[20];
        unsigned char age;
        short int weight;
        float gpa;
        };
//struct differ from union bec struct  allocate memory for each and dont share $
        typedef struct person P;
        P p1,p2,p3,p4,p5;
        struct person p1;
        struct person p2;
        struct person p3,p4,p5;

        p1.age = 29;

Keywords

cprog Keywords

Standard I/O (STDIO, STDOUT, STDERR)…xxxx ■ logic and operators (and, or, not, xor)

■ Scope (Block, Local, Global, File)

■ Type Casting

■ Structures (Declaration, Accessing Elements, Pointers to)

■ typedef, enum, union

■ Functions, Parameters (Pass by: Value, Address, Reference), Return Types, Recursion, Command-line arguments

■ Compiler, Preprocessor, Flags, Assembler, Linker, Multi-file programs (how to structure, how to compile)……x

■ I/O Streams (cin, cout, cerr, stream operators) [C++]……xxx

■ Namespaces [C++]…xxx

■ Type Casting Operators, Const-Volatility Specifiers (const, volatile) [C++]

■ Classes (Objects, Constructor, Destructor, Access Control, Public, Protected, Private, Friend, “this” pointer) [C++]…..xxxxx

■ Inheritance (single, multiple Inheritance), Polymorphism/Virtual Functions, Abstract Base Class [C++]

■ Overloading (Functions, Operators) [C++]

■ Exception Handing (throw, try, catch) [C++]

■ Templates, STL (Standard Template Library) [C++]

Compiler, Preprocessor, Flags, Assembler, Linker, Multi-file programs (how to structure, how to compile)

Flags In programming, a flag is a predefined bit or bit sequence that holds a binary value. Typically, a program uses a flag to know when a data stream ends and new data begins. good example is flags used in networking. For example: 1010100 (flag to say hey begin recording) 0101101 (data) 0111011 (data) 0101011(flag to say hey end of data stream)

assembler Is a program that takes basic text in a programing laguage and translates it into bits the processor uses for excution of task. is you are engineer that builds computers you would most likly know assembly laguage.

Binary Code code made of 0's and 1's known as low level programming, called machine language that most programmers don't work with but compiler use.(Assembly language)

Preprocessor program started by the compiler as the first part of translation,it handles #include, #define, and #if.by replaceing #include with stdlib.h or other hearder files you have listed example #include <stdlib.h>

cprog Keyword 10

I/O Streams (cin, cout, cerr, stream operators) [C++]

Definition

in c you use stdin, stdout, and stderr. in C++ you use cin, cout, and cerr. cout- is an object of class that represents the standard output stream. cin- Standard input stream (object) cerr- Standard output stream for errors (object)

Demonstration

<iostream> in C++ example while (true) {

 cout << "Please enter a valid number: ";
 getline(cin, input);

in c int value =0; printf(“please enter a number:\n”); fscanf(stdin,%d,&value);

Classes (Objects, Constructor, Destructor, Access Control, Public, Protected, Private, Friend, “this” pointer) [C++]

Definition

c++ is a way to maintain your code through c lasses to make code more organized. in this class there is there is a public,private protected. these are the access for the class. what is in public can be accessed from anyone. thoses in private cannot be accessed at all from anyone unless there is a way to access it in protected like in the below example with get x.

Demonstration
#ifndef _GATE_H
#define _GATE_H
 
//sample code for classes dealing with inheritance
//abstract base class..
//base class
 
class gate{
        public:
                gate(); // constructor
                bool getx();
                void seta(bool);
                void setb(bool);
        protected:
                void setx(bool);
                bool a;
                bool b;
        private:
                bool x;
};
#endif

Type DEf

Definition

When using same type of data for many declarations, you can customize its name and “re use it with out re writing the name again and again . In C++, the type def keyword allows you to create an alias for a data type. The formula to follow is: typedef [attributes] DataType AliasName; The typedef keyword is required. The attribute is not.

Enum short for enumerated data allow a user to define a fixed set of words that a variable of type enum can use as its value. The words are assigned integer values by the compiler so enum values can be compared.

A union is comprised of a collection of variables of different types, just like a structure. However, with unions, you can only store information in one field at a time. Once a new value is assigned to a field, any existing data is overwritten with new data. The use of unions can save memory if you have a grouping of data and only one of the types is used at a time. The size of a union is dependent on the size of it's largest data member.

Demonstration
struct person{
        char *name;//or --char name[20];
        unsigned char age;
        short int weight;
        float gpa;
        };
//struct differ from union bec struct  allocate memory for each and dont share like union
        typedef struct person P;
        P p1,p2,p3,p4,p5;
        struct person p1;
        struct person p2;
        struct person p3,p4,p5;

        p1.age = 29;

Standard I/O (STDIO, STDOUT, STDERR)

Definition

stdio or standard input is defaulted to the the keyboard. standard output is defaulted to the screen. stderr is also defaulted to the screen for err msgs

Inheritance (single, multiple Inheritance), Polymorphism/Virtual Functions, Abstract Base Class [C++]

Definition

is a thing that is inherited. example: B can inherit A and be a child

Demonstration

Demonstration of the chosen keyword.

gate :: gate() {

      a=b=x=false;

} bool gate :: getx() {

      return(x); //return x to have acces to x

}

void gate :: seta(bool a) {

      this->a=a; //property of c++ refer to self

} void gate :: setb(bool b) {

      this->b=b;//-> this is a pointer

} void gate :: setx(bool x) {

      this->x=x;

}

Namespaces [C++]

Namespaces allow to group like classes, objects and functions under a name.

namespace myNamespace {

int a, b;

}

Funtions,parameters

Definition

A function in the C programming language is code that has a name and property that are reusable. This means that a function can be called on from as many different points in the program as needed.

A Parameter in the C programming language is any data that is passed to a function. Demonstration

Demonstration
#include<stdio.h>
#include<stdlib.h>
 
int sum(int, int, int, int); //function and parameters expected
 
float avg(int, int, int, int); //function and parameters expected
 
int main(int n1)//main is accepting a integer value for parameter 
 
{
return(0);
}

cprog Objective

cprog Objective

establish a better understanding of c and c++

Definition

the objective entails learning about type defs classes and working projects

Method

create a program that incorporates classes with code and type defs

Analysis

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

  • How did you do?
  • I did ok
  • Is there room for improvement?
  • Yes
  • Could the measurement process be enhanced to be more effective?
  • Yes
  • Do you think this enhancement would be efficient to employ?
  • Yes
  • Could the course objective be altered to be more applicable?Yes
  • How would you alter it? I wouldn't

unix Keywords

■ $PATH….X

■ Job control…….x

■ wildcards……x

■ tab completion…..x

■ Cron/Crontab…….x

■ Pattern Matching………x

■ Regular Expressions…….x

■ Shell Scripting…..x

unix Keyword 9

shell scripting

Definition

shell scripting is a small program essentialy that contains commands such as command line task such as grep, ls, mv, and cp. when you run the script it it excute these for you instead of typing all theses things.

Demonstration

ls ~ df who

is in script.sh

 lab46:~$ ./script.sh
Desktop          archive2.zip          count.c     mail
Documents        archives              data        motd
Downloads        archivescombined.tar  date        multitask.lab.txt
Maildir          at                    dateyears   output
Music            badname               devel       phenny
Pictures         badname.tgz           file        phenny.tar.bz2
Public           bin                   forloop.sh  script.sh
Templates        botscript.sh          guess1.sh   src
Videos           class_notes           lab1        src.bak
age.sh           classlog.c            lab2        the answer.txt
archive1.tar.gz  count                 loop.sh
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/xvda1             4128448   2522072   1396664  65% /
tmpfs                   784300         0    784300   0% /lib/init/rw
udev                    755640        36    755604   1% /dev
tmpfs                   784300         4    784296   1% /dev/shm
/dev/xvda2              253871     12859    227905   6% /tmp
nfs:/home            2930056576 1434124544 1495932032  49% /home
nfs:/lib/mail        2930056576 1434124544 1495932032  49% /var/mail
skinney1 pts/8        2012-03-17 11:36 (cpe-24-94-52-91.stny.res.rr.com)
rmatsch  pts/16       2012-03-17 11:46 (user-10bj433.cable.mindspring.com)
jjohns43 pts/24       2012-01-23 12:18 (cpe-74-65-82-173:S.0)
smalik2  pts/29       2012-03-17 10:49 (cpe-69-205-204-88.stny.res.rr.com)
skinney1 pts/35       2012-03-16 10:15 (65-124-85-125.dia.static.qwest.net)
mfaucet2 pts/65       2012-03-09 17:09 (55:S.0)
smalik2  pts/27       2012-01-25 14:53 (cpe-69-205-204-88:S.0)
wedge    pts/28       2012-03-17 10:02 (telstar.lair.lan)
jdavis34 pts/22       2012-03-06 12:57 (cpe-69-205-141-69:S.0)
jjohns43 pts/82       2012-02-27 11:03 (cpe-74-65-82-173:S.0)
lab46:~$
PATH(unix)
Definition

PATH is an environmental variable that specifies a set of directories where executable programs are located.

Demonstration
lab46:~$export PATH=$PATH:/home/rmatsch/src/unix

Job control (unix)

Definition

Job control allow you to have the system work on a job in the background while you do something else . If you are simply trying to get logged out, but have encountered the “There are stopped jobs” message

Useful Commands control-z Stop (don't kill) the foreground job, and then return to the shell

Check the status of jobs in the current session ps -u username Check the status of processes, including those from other sessions. On BSD systems, use 'ps -gx'. kill -9 %1 Kill a job, by specifying its job number after the percent sign kill -9 123 Kill a process, by specifying its process id (PID) number bg Run the most recently stopped job in the background fg Bring most recently background job to the foreground fg %1 Bring a job to foreground by specifying its job number after the percent sign

A daemon is a computer program that runs in the background as a process, instead of running in the foreground. below is an example of a deamon running in back ground and a command to look at the root processes.

Demonstration

inetd or init

 lab46:~$ ps -u root
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0   8356   720 ?        Ss   Jan17   0:41 init [2]
root         2  0.0  0.0      0     0 ?        S    Jan17   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    Jan17   0:05 [migration/0]
root         4  0.0  0.0      0     0 ?        S    Jan17   0:08 [ksoftirqd/0]
root         5  0.0  0.0      0     0 ?        S    Jan17   0:00 [watchdog/0]
root         6  0.0  0.0      0     0 ?        S    Jan17   0:04 [migration/1]
root         7  0.0  0.0      0     0 ?        S    Jan17   0:03 [ksoftirqd/1]
root         8  0.0  0.0      0     0 ?        S    Jan17   0:00 [watchdog/1]
root         9  0.0  0.0      0     0 ?        S    Jan17   5:40 [events/0]
root        10  0.0  0.0      0     0 ?        S    Jan17   3:53 [events/1]
root        11  0.0  0.0      0     0 ?        S    Jan17   0:00 [cpuset]
root        12  0.0  0.0      0     0 ?        S    Jan17   0:00 [khelper]
root        13  0.0  0.0      0     0 ?        S    Jan17   0:00 [netns]
root        14  0.0  0.0      0     0 ?        S    Jan17   0:00 [async/mgr]
root        15  0.0  0.0      0     0 ?        S    Jan17   0:00 [pm]
root        16  0.0  0.0      0     0 ?        S    Jan17   0:00 [xenwatch]
root        17  0.0  0.0      0     0 ?        S    Jan17   0:00 [xenbus]
root        18  0.0  0.0      0     0 ?        S    Jan17   0:06 [sync_supers]
root        19  0.0  0.0      0     0 ?        S    Jan17   0:07 [bdi-default]
root        20  0.0  0.0      0     0 ?        S    Jan17   0:00 [kintegrityd/0]
root        21  0.0  0.0      0     0 ?        S    Jan17   0:00 [kintegrityd/1]
root        22  0.0  0.0      0     0 ?        S    Jan17   0:00 [kblockd/0]
root        23  0.0  0.0      0     0 ?        S    Jan17   0:00 [kblockd/1]
root        24  0.0  0.0      0     0 ?        S    Jan17   0:00 [kseriod]
root        27  0.0  0.0      0     0 ?        S    Jan17   0:00 [kondemand/0]
root        28  0.0  0.0      0     0 ?        S    Jan17   0:00 [kondemand/1]
root        29  0.0  0.0      0     0 ?        S    Jan17   0:02 [khungtaskd]
root        30  0.0  0.0      0     0 ?        S    Jan17   0:20 [kswapd0]
root        31  0.0  0.0      0     0 ?        SN   Jan17   0:00 [ksmd]
root        32  0.0  0.0      0     0 ?        S    Jan17   0:00 [aio/0]
root        33  0.0  0.0      0     0 ?        S    Jan17   0:00 [aio/1]
root        34  0.0  0.0      0     0 ?        S    Jan17   0:00 [crypto/0]
root        35  0.0  0.0      0     0 ?        S    Jan17   0:00 [crypto/1]
root        38  0.0  0.0      0     0 ?        S    Jan17   0:00 [khvcd]
root       123  0.0  0.0      0     0 ?        S    Jan17   0:14 [kjournald]
root       170  0.0  0.0  10408     4 ?        S<s  Jan17   0:00 udevd --daemon
root       222  0.0  0.0  10404     4 ?        S<   Jan17   0:00 udevd --daemon
root       223  0.0  0.0  10404     4 ?        S<   Jan17   0:00 udevd --daemon
root       355  0.0  0.0      0     0 ?        S    Jan17   0:49 [rpciod/0]
root       356  0.0  0.0      0     0 ?        S    Jan17   0:00 [rpciod/1]
root       373  0.0  0.0      0     0 ?        S<   Jan17   0:00 [kslowd000]
root       374  0.0  0.0      0     0 ?        S<   Jan17   0:00 [kslowd001]
root       375  0.0  0.0      0     0 ?        S    Jan17   0:28 [nfsiod]
root       395  0.0  0.0      0     0 ?        S    Jan17   0:03 [kjournald]
root       495  0.0  0.0   6748   596 ?        Ss   Jan17   0:00 dhclient -v -pf
root       788  0.0  0.0  43220     4 ?        S    Jan17   0:00 supervising sys
root       789  0.0  0.1  51592  2912 ?        Ss   Jan17   0:39 /usr/sbin/syslo
root       890  0.0  0.0  10208   104 ?        Ss   Jan17   0:00 /usr/sbin/inetd
root       921  0.0  0.0  43112   344 ?        Ss   Jan17   0:05 /usr/sbin/sshd
root      1014  0.0  0.0      0     0 ?        S    Jan17   0:00 [nfsv4.0-svc]
root      1037  0.0  0.0   5928     8 hvc0     Ss+  Jan17   0:00 /sbin/getty 384
root      1780  0.0  0.1  74000  2296 ?        SN   Mar09   0:00 /USR/SBIN/CRON
root     15461  0.0  0.1  59236  2076 ?        Ss   Jan19   0:12 /usr/sbin/cron
root     21168  0.0  0.0      0     0 ?        S    Mar14   0:01 [flush-202:1]
root     25915  0.0  0.2  89100  3932 ?        SNs  02:23   0:00 sshd: csit2310
root     27443  0.0  0.2  89100  3964 ?        SNs  Mar16   0:00 sshd: skinney1
root     28768  0.0  0.0      0     0 ?        S    08:35   0:00 [flush-0:17]
root     29506  0.0  0.2  89100  3960 ?        SNs  10:02   0:00 sshd: wedge [pr
root     30082  0.0  0.2  89100  3988 ?        SNs  10:48   0:00 sshd: smalik2 [
root     30157  0.0  0.1  58860  2076 ?        Ss   Mar14   0:02 /usr/sbin/rpc.i
root     30213  0.0  0.1 167308  2236 ?        Ssl  Mar14   0:16 /usr/sbin/nscd
root     30246  0.0  0.2  89100  4000 ?        SNs  11:08   0:00 sshd: smalik2 [
root     30373  0.0  0.0      0     0 ?        S    11:28   0:00 [flush-202:2]
root     30418  0.0  0.2  89100  3984 ?        SNs  11:35   0:00 sshd: jdavis34
root     30435  0.0  0.2  89100  4000 ?        SNs  11:36   0:00 sshd: skinney1
root     30530  0.0  0.2  89100  3992 ?        SNs  11:46   0:00 sshd: rmatsch [
root     31447  0.0  0.1  74000  2296 ?        SN   Mar09   0:00 /USR/SBIN/CRON
root     31763  0.0  0.1  74004  1956 ?        SN   Mar14   0:00 /USR/SBIN/CRON
root     32271  0.0  0.1  74000  2296 ?        SN   Mar09   0:00 /USR/SBIN/CRON
root     32506  0.0  0.1  74000  2300 ?        SN   Mar13   0:00 /USR/SBIN/CRON
lab46:~$

unix Keyword 12

cron/crontab

Definition

cron tab is a task scheduler.It is a time based which runs periodically at certain times or dates, used to automate system processes.

Demonstration
lab46:~$ crontab -e

 # Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command

Wild Cards(Unix)

Definition

characters that are very powerful and help a great deal when in UNIX. the special characters enable a user to control the output of commands without having to specify the exact name of a file.

demonstration

* zero or more of “any” character

? used to represent one of “any” character

\ will ignore such things as space if the variable name isn't one string.

” ” (or ' ') quote the enclosed characters

[ ] character class - match any of the enclosed characters.

[^ ] inverted character class - do not match any of the enclosed characters.

pattern matching(unix)

Definition

Pattern matching a way to search in unix which enables the user to look for files.

Demonstration

Using ls(1), list files that match the following patterns: a. Only files that begin with a lowercase vowel. b. All files that end with a .s c. All files that do not start with a vowel, yet end with a .s d. Only 3 character filenames that don't end with a consonant. e. Explain your strategy and reasoning for constructing an effective pattern for each part of this question

a. Using ls in the given directory, show me how you'd list only files

   that begin with a lowercase vowel:
      ls a* e* i* o* u*

b. Using ls in the given directory, show me how you'd list only files

   that end with a .s:
      ls *.s

c. Using ls in the given directory, show me how you'd list only files

   that do not start with a vowel, yet end with a .s:
      ls  [b-d,f-h,j-n,p-t,v-z]**.s

d. Using ls in the given directory, show me how you'd list only the

   files consisting of just 3 character filenames that don't end with a
   consonant:
lab46:/var/public/unix/patterns$ ls a* e* i* o* u*
a.b.c.d.e.f.s  abd                         i3
a39487y        abe                         i4
a6.c           abf                         i5.s
a7.d           ac.s                        i6.s
a8.e           aca                         i7.s
a9.f           ad.s                        ive_got_a_beautiful_feeling
aaa            alab5.s                     o_what_a_beautiful_day
aab            alab6.s                     o_what_a_beautiful_morning.s
aac            e11                         u_2
aad            e8933                       uey
aae            e9038                       uey2
aaf            e904385                     ueya
ab.s           ee.s                        ueyai
aba            everythings_going_my_way.s  ueyed
abb            i1                          uint
abc            i2
lab46:/var/public/unix/patterns$

Tab completion (unix)

tab completion

Definition

tab completion is a command line feature that allows you to type some of a command and have the command line finish it when you hit the tab key. kinda like a auto complete

Demonstration

Demonstration of the chosen keyword.

lab46:/var/public/unix/patterns$ l (tab)
last             less             lispmtopgm       lrrdNode
lastb            lessecho         listres          ls
lastlog          lessfile         ln               lsattr
latin2ascii.py   lesskey          lnstat           lscpu
lcf              lesspipe         loadkeys         lsinitramfs
ld               let              loadunimap       lsmod
ld.bfd           lex              local            lsof
ld.gold          lexgrog          locale           lspci
ldapadd          lft              localedef        lspgpot
ldapcompare      lft.db           lockfile         lsusb
ldapdelete       lftp             lockfile-check   luit
ldapexop         lftpget          lockfile-create  lwp-download
ldapmodify       libnetcfg        lockfile-remove  lwp-dump
ldapmodrdn       libpng-config    lockfile-touch   lwp-mirror
ldappasswd       libpng12-config  loggen           lwp-request
ldapsearch       line             logger           lwp-rget
ldapurl          link             login            lxterm
ldapwhoami       links            logname          lynx
ldd              links2           logout           lynx.cur
ldrdf            linux32          look             lzmainfo
leaftoppm        linux64          lorder

unix Keyword 16

regular expressions

Regular Expression Symbol . Match any character * Match 0 or more of the preceding

$ End of line or string [ ] Character class - match any of the enclosed characters [^ ] Negated character class - do not match any of the enclosed characters \< Beginning of word \> End of word

Demonstration

grep '^[b-d][aeiou]' /etc/passwd

unix Objective

unix Objective

be able to write a simple shell scipt that contains file manipulation, and irc bot configuration.

Definition

the objective entails making a script to do multiple task incoporatiing things which have already learned allong with new task.

Method

have students given many task and allow students to write all of these task in a script to be performed in a single script.

Measurement

tell students to creat a script to do thing they know how to do via command line and also do task they dont know.

Analysis

Reflect upon your results of the measurement to ascertain my achievement i did alright but there is always room for inprovmemt.

Experiments

Experiment 4

Question

What happends when you leave out a semi colin on a struct.

Resources

struct weki pages

Hypothesis

Based on what i read i think the result of your experiment will be a compile erroor. i believe this because funtions do not need them after curly brace but a struct would have to

Experiment

i will create a struct and compile it to see if it compiles with out errors.

Data

like i thought the semi colin is very important. i recieved a error when compiling

Analysis

Based on the data collected:

my hypothesis correct, and applicable for the data collected.

Conclusions

based on the experiment performed and data collected leaving a semi colin out of a struct will cause an error when compiling. Error exspected expression.

Experiment 5

Question

when defining a funtion can you put a return type on a void funtion()

Resources

class notes void main() and int main()

Hypothesis

based on class notes i the void main cannot have a return valuenbecause void main mean nothing is being returned.

Experiment

i will create a void sum funtion and then type retutn(0); at the end pf the funtion. i will then compile and see what happends if any/

Data

lab46:~/src/cprog/project2$ gcc -o prog2f prog2f.c
prog2f.c: In function 'sum':
prog2f.c:56: warning: 'return' with a value, in function returning void
lab46:~/src/cprog/project2$

Analysis

Based on the data collected my hypothesis was not correct but it was applicable. there was no short commings ut just a little more going on then exspected

===Conclusions===

based on the experiment performed and data collected having a return type to a void funtion will give a warning but will still compile.

Retest 2

State Experiment

brobbins exsperiment 1

Resources

Evaluate their resources and commentary. Answer the following questions:

  • Do you feel the given resources are adequate in providing sufficient background information?
  • Yes
  • Are there additional resources you've found that you can add to the resources list?
  • No
  • Does the original experimenter appear to have obtained a necessary fundamental understanding of the concepts leading up to their stated experiment?
  • Yes
  • If you find a deviation in opinion, state why you think this might exist.
  • No the hypothesis looks looks good.

Hypothesis

Based on what I have learned about the C programming language thus far, I believe that the use of the exit command within a function will only cause the function to exit and not the entire program due to the fact that the exit argument would only be in scope with the current function and not the rest of the program.

  • Do you feel their hypothesis is adequate in capturing the essence of what they're trying to discover?
  • Yes
  • What improvements could you make to their hypothesis, if any?
  • None

Experiment

  • Are the instructions correct in successfully achieving the results?
  • Yes
  • Is there room for improvement in the experiment instructions/description? What suggestions would you make? No accomplishes the what is exsperimented.
  • Would you make any alterations to the structure of the experiment to yield better results? What, and why? No the structire of the exsperiment is is sufficient enough.

Data

This is the original code

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
 
int iseven(int value)
{
        int tmp;
        tmp=value % 2;
        return(tmp);
}
 
void add(int *list, int total, int value)
{
        int i, s=0;
        for(i=0; i < total; i++)
        {
                if(*(list+i)==-1)
                {
                        *(list+i)=value;
                        s=i;
                        break;
                }
        }
}
 
int *init(int total, int *status)
{
        int i, *tmp;
        *status=0;
        if(total > 0)
        {
                tmp=(int*)malloc(sizeof(int)*total);
                for(i=0; i < total; i++)
                {
                        *(tmp+i)=-1;
                }
                *status=1;
        }
        return(tmp);
}
 
int main(int argc, char **argv)
{
        int *list, i, x=0;
        list=init(atoi(*(argv+1)),&x);
        if(x==0)
        {
                fprintf(stderr, "Error on initialization!");
                exit(1);
        }
        for(i=0; i < atoi(*(argv+1)); i++)
        {
                add(list, atoi(*(argv+1)), (rand()%atoi(*(argv+2))));
        }
        for(i=0; i < atoi(*(argv+1)); i++)
        {
                if(iseven(*(list+i))==0)
                {
                        fprintf(stdout, "%d is even\n", *(list+i));
                }
                else
                        fprintf(stdout, "%d is odd\n", *(list+i));
        }
        return(0);
}

This is the output received from the unmodified code.

lab46:~/src/cprog$ ./iseven 5 30
13 is odd
16 is even
27 is odd
25 is odd
23 is odd
lab46:~/src/cprog$

The following is the code that has been modified to reflect the question above. Note the change in the “add” function, the “break” statement has been changed to an “exit” statement with a return code of zero. Also note the inclusion if the new printf statements within each function. These are included so I am able to tell how far the program progresses.

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
 
int iseven(int value)
{
        printf("Diag 1\n");
        int tmp;
        tmp=value % 2;
        return(tmp);
}
 
void add(int *list, int total, int value)
{
        printf("Diag 2\n");
        int i, s=0;
        for(i=0; i < total; i++)
        {
                if(*(list+i)==-1)
                {
                        *(list+i)=value;
                        s=i;
                        exit(0);
                }
        }
}
 
int *init(int total, int *status)
{
        printf("Diag 3\n");
        int i, *tmp;
        *status=0;
        if(total > 0)
        {
                tmp=(int*)malloc(sizeof(int)*total);
                for(i=0; i < total; i++)
                {
                        *(tmp+i)=-1;
                }
                *status=1;
        }
        return(tmp);
}
 
int main(int argc, char **argv)
{
        printf("Diag 4A\n");
        int *list, i, x=0;
        printf("Diag 4B\n");
        list=init(atoi(*(argv+1)),&x);
        printf("Diag 4C\n");
        if(x==0)
        {
                fprintf(stderr, "Error on initialization!");
                exit(1);
        }
        printf("Diag 4D\n");
        for(i=0; i < atoi(*(argv+1)); i++)
        {
                printf("Diag 4Da\n");
                add(list, atoi(*(argv+1)), (rand()%atoi(*(argv+2))));
                printf("Diag 4Db\n");
        }
        for(i=0; i < atoi(*(argv+1)); i++)
        {
                if(iseven(*(list+i))==0)
                {
                        fprintf(stdout, "%d is even\n", *(list+i));
                }
                else
                        fprintf(stdout, "%d is odd\n", *(list+i));
        }
        return(0);
}

The following is the resulting output after the modifications.

lab46:~/src/cprog$ ./iseven 5 30
Diag 4A
Diag 4B
Diag 3
Diag 4C
Diag 4D
Diag 4Da
Diag 2
lab46:~/src/cprog$

Analysis

  • Does the data seem in-line with the published data from the original author?
  • Yes every thing comes out good
  • Can you explain any deviations?
  • There was no deviations from experiment
  • How about any sources of error?
  • Code could have been written a little better
  • Is the stated hypothesis adequate?
  • Yes stated hypothesis is adequate

Conclusions

  • What conclusions can you make based on performing the experiment?
  • With the data collected the hypothesis is correct
  • Do you feel the experiment was adequate in obtaining a further understanding of a concept?
  • yes
  • Does the original author appear to have gotten some value out of performing the experiment?
  • Yes
  • Any suggestions or observations that could improve this particular process (in general, or specifically you, or specifically for the original author).
  • No

Part 3

Entries

Entry 9: April 10, 2012

In my UNIX class i learned how to better search through files and use the head(1) and sed(1) utility to take text out of the file i did not want. sed 's/pattern/replacement/g' = pattern searching for and then replace pattern searching for with this replacement and g means globally.head -25 file.txt = -n for number of lines you want to print of the file you choose which could then be piped to sed a stream editor to remove unwanted text. a basic line may look like this

head -25 file.txt | sed -e 's/[a-z]*5/:/g' print first 25 lines of file.txt and then search for text that start with a to z and end in 5 and once found replace that with colon globally in the file.

Entry 10: April 13, 2012

C++ class

A program can be split up into multiple files making it easier to edit and understand, especially in the case of large programs but also allows the individual parts to be compiled independently.

*when compiling a large program with multiple header file remember to add this line in the header file so you do not include the same header file twice in your program.

#ifndef _HEADERFILENAME_H #define _HEADERFILENAME_H

#endif

Entry 11: April 14, 2012

g++ -o prog file1.o file2.o file3.o compile c++ code into one executable named prog with the object files: file1 file2 file3. then you can now run ./prog on the command line because it is now an executable file.

To produce only .o files from source files without doing any linking invoke -c option

Entry 12: April 19,2012

some html i did in unix class that diplayes an image of myself and some general info

<html>
<title> RM Lab46 Homepage</title>
<body>
<center>Unix Homepage by Robert Matsch</center>
<img src="player.jpg"  height="42" width="42" />


<strong>Who am I :</strong>
<p>My name is Robert matsch, I am currently a student at corning community college. Upon completion of my Computer Information Science degreein in may 2012  i am attending RIT for the fall of 2012. I am majoring in software engineering and planning to live in california once i graduate to work with my uncle and be part owner in a private consulting company.I enjoy listening to music, being active, riding my motorcycle and best of all spending time with friends and family.
</p>
<hr>
<br> Top 6 movies:
<ol>
<li>Step Brothers</li>
<li>Hangover 1 and 2 </li>
<li>Finding Nemo</li>
<li>Bad Boys II</li>
<li>Talladega Nights</li>
<li>k-pax</li>
</ol>
<p>


</p>
<br> who is I ?
</body>
</html>

<html> <title> RM Lab46 Homepage</title> <body> <center>Unix Homepage by Robert Matsch</center> <img src=“player.jpg” height=“42” width=“42” />

<strong>Who am I :</strong> <p>My name is Robert matsch, I am currently a student at corning community college. Upon completion of my Computer Information Science degreein in may 2012 i am attending RIT for the fall of 2012. I am majoring in software engineering and planning to live in california once i graduate to work with my uncle and be part owner in a private consulting company.I enjoy listening to music, being active, riding my motorcycle and best of all spending time with friends and family. </p> <hr> <br> Top 6 movies: <ol> <li>Step Brothers</li> <li>Hangover 1 and 2 </li> <li>Finding Nemo</li> <li>Bad Boys II</li> <li>Talladega Nights</li> <li>k-pax</li> </ol> <p>

</p> <br> who is I ? </body> </html>

Entry 12: April Day, 2012

This is a sample format for a dated entry. Please substitute the actual date for “Month Day, Year”, and duplicate the level 4 heading to make additional entries.

As an aid, feel free to use the following questions to help you generate content for your entries:

  • What action or concept of significance, as related to the course, did you experience on this date?
  • Why was this significant?
  • What concepts are you dealing with that may not make perfect sense?
  • What challenges are you facing with respect to the course?

Remember that 4 is just the minimum number of entries. Feel free to have more.

cprog Keywords

•	logic and operators (and, or, not, xor)
•	Scope (Block, Local, Global, File)
•	Type Casting
•	Structures (Declaration, Accessing Elements, Pointers to)
•	Type Casting Operators, Const-Volatility Specifiers (const, volatile) [C++]
•	Overloading (Functions, Operators) [C++]
•	Exception Handing (throw, try, catch) [C++]
•	Templates, STL (Standard Template Library) [C++]
Logic operators
Definition

logic operators are a logical operation on one or more logic inputs that produces a single logic output

Demonstration
a b  |  and   or    xor   nor   xnor  nand  notb  nota
F T  |  F     T     T     F     F     T      F     T
T T  |  T     T     F     F     T     F      F     F
F F  |  T     F     F     T     T     T      T     T
T F  |  F     T     T     F     F     T      T     F
Type casting
Definition

Converting one type of data into another type of data.

Demonstration
short a=2000;
int b;
b = (int) a;    
b = int (a);
or
short a=2000;
int b;
b=a;
Templates
Definition

Templates in C++ template are classes to provide common programming data structures and functions. STL- standard template library is a library of templates

Demonstration
#include<iostream>
using namespace std;

template <class T>
void myfunc (T val1, T val2, T val3)
{
        T result;
        result = val1 + val2 + val3;

        cout << "First value is: " << val1 << endl;
        cout << "Second value is: " << val2 << endl;
        cout << "Third value is: " << val3 << endl;

        cout << "The sum of all three are: " << result << endl;

        cout << "The average of all three are: " << (T)(result/3) << endl;
}

int main()
{
        // some c code here 
        return 0;
}
Overloading Functions, Operators
Definition

You can redefine a function of most built-in operators in C++ by overloading globally or on a class. key point * Overloaded operators are implemented as functions and can be “member functions or global functions”.

You can also overload a function name by declaring more than one function with the that name in the same scope. when the program is being run and the function is call the program matches parameters up to select the right function.

Demonstration

Operator overloading

#include <iostream>
using namespace std;
 
class complx
{
      double real,
             imag;
public:
      complx( double real = 0., double imag = 0.); // constructor
      complx operator+(const complx&) const;       // operator+()
};
 
// define constructor
complx::complx( double r, double i )
{
      real = r; imag = i;
}
 
// define overloaded + (plus) operator
complx complx::operator+ (const complx& c) const
{
      complx result;
      result.real = (this->real + c.real);
      result.imag = (this->imag + c.imag);
      return result;
}
 
int main()
{
      complx x(4,4);
      complx y(6,6);
      complx z = x + y; // calls complx::operator+()

and now function overloading

#include <iostream>
using namespace std;

void print(int i) {
  cout << " Here is int " << i << endl;
}
void print(double  f) {
  cout << " Here is float " << f << endl;
}

void print(char* c) {
  cout << " Here is char* " << c << endl;
}

int main() {
  print(10);
  print(10.10);
  print("ten");

and now the output from this function over loading

lab46:~$ ./funoverl
 Here is int 10
 Here is float 10.1
 Here is char* ten
Exception Handing (throw, try, catch) [C++]
Definition

key words that can “catch exceptions” by placing a portion of code under exception inspection and enclosing that portion of code in a “try block”. it works When an exception circumstance comes about within that block, the exception is then thrown which transfers the control to the exception handler. If no exception is thrown the code continues normally.

Demonstration
#include <iostream>
using namespace std;
 
int main () {
  try
  {
    throw 20;
  }
  catch (int e)
  {
    cout << "An exception occurred. Exception Nr. " << e << endl;
  }
  return 0;
}
Scope (Block, Local, Global, File)
Definition

block: C++ names can only be used in parts of a program called the “scope” of the name. unless otherwise acres from a member of that class scope. this is very important in C++ because scope determines when variables local to the scope are initialized.

Local scope:A name declared within a block is accessible only within that block and blocks enclosed by it and only after the point of declaration.

File scope: Any name declared outside all blocks or classes has file scope also known as namespace scope.

global scope: is names with file scope that are not declare objects are global names.

Demonstration
local scope 
{
        int i;
    }

Notice the declaration of i is in a block enclosed by curly braces so i has local scope and is never accessible because there is no code accesses before the closing curly brace.

class area()
{
    int x;
    int y;
};

x and y can be used to access the class area through “.”or “→”

Type Casting Operators, Const-Volatility Specifiers (const, volatile) [C++]
Definition

constant : makes that the type is constant but also the object shall not be modified. In doing so it may you may recieve undesired/undefined results such as compile time error compile-time error.

volatile: makes the type volatile and the object then be modified so that the compiler doesn't yell at you.

Demonstration
       const int five = 5;
       const double pi = 3.141593;

const objects may not be changed below is an example: <Code>

#include <stdio.h> #include <stdlib.h> int main() {

     int result=0;
     const int five = 5;
     const double pi = 3.141593;
     pi = 3.2;
     five = 6;
     result=five+pi;

return(0); } </code> compile msg below

lab46:~$ gcc -o const const.c
const.c: In function 'main':
const.c:9: error: assignment of read-only variable 'pi'
const.c:10: error: assignment of read-only variable 'five'
Structures (Declaration, Accessing Elements, Pointers to)
Definition

Declaring : a structure it is in the form of a block of data which can contain different data types depending on means of a structure declaration.

Accessing elements: structure accessing is done by specify both the structure name (name of the variable) and the member name when accessing information stored in a structure.

Point:you can point to structs by deference them below is example

 
  struct tag *st_per;

and we point it to our example structure with:

  st_per = &my_struct;
Demonstration
struct person{
        char *name;//or --char name[20];
        unsigned char age;
        short int weight;
        float gpa;
        };
//struct differ from union bec struct  allocate memory for each and dont share $
        typedef struct person P;
        P p1,p2,p3,p4,p5;
        struct person p1;
        struct person p2;
        struct person p3,p4,p5;
 
        Accessing Members of a Structure
        p1.age = 29;
 
 
point to :
struct person *st_per;
    st_per = &my_struct;
(*st_per).age = 63;

cprog Objective

cprog Objective

The course objective is to be able to successfully develop C code of a desired program. The program should work and any problems that come about can be figure out and finally manage the code with C++ and abstract details away for security and neatness.

Method

Develop a program that will allow a simpler way of doing something from creating a program of your choice. Have what you wish to be able to do and then program with the requirements chosen. produce a finished result

Measurement

I have develop a program that i thought was going to be easy and turned out my requirement i want i did not achieve so i changed them a little. the program accepts string and compares string to string for user authentication.

Analysis

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

  • How did you do?
  • i did well but could learn a great deal more
  • Is there room for improvement?
  • yes
  • Could the measurement process be enhanced to be more effective? Of course this is only mt perspective.

unix Keywords

■The UNIX Shell

■ Environment variable

■ Source Code, Object Code, Binary Code, Library……x

■ Source Code, Object Code, Binary Code, Library

■ Filtering

■ networking, UNIX Networking Tools

■ Security

■ X Window System

Filtering (Unix)
Definition

filtering is a way to process text in a usable manner for the goal that is in mind.

Demonstration

some filtering utilities

  cat(1) - concatenate files
  cut(1) - cut text
  grep(1) - globally search for regular expression and print
  head(1) - print first “n” lines of output
  sed(1) - stream editor
  sort(1) - sort output
  tail(1) - print last “n” lines of output
  tr(1) - translate characters
  uniq(1) - filter out duplicate lines from sorted file
  wc(1) - word count
lab46:~$ cat sample.db
name:sid:major:year:favorite candy*
Jim Smith:105743:Economics:Sophomore:Lollipops*
Adelle Wilson:594893:Sociology:Junior:Ju-Ju Fish*
Sarah Billings:938389:Accounting:Freshman:Tic-Tacs*
Eric Vincent:1001119:Biology:Freshman:Lollipops*
Linus Torvalds:4432001:Computer Science:Senior:Snickers*
Alan Cox:40049300:Computer Science:Senior:Whoppers*
Alan Turing:40030333:Computer Science:Senior:Rock Candy*
Eric Vincent:1001119:Biology:Freshman:Lollipops*
John Doe:0000000:Unknown:Freshman:unknown*
Leet Haxzor:31337:Business:Sophomore:Gobstoppers*
Matthew Green:439478:Philosophy:Junior:Necco Wafers*
Megan Tanner:372233:Physics:Junior:Zero Bar*
Junior Mint:2228484:Liberal Arts:Junior:Junior Mints*
Alan Wilson:22908948:Economics:Freshman:Whoppers*
Kris Warner:8383833:Biology:Senior:Mars Bar*
Jill Ashley:9939392:Chemistry:Freshman:Warheads*
Francois Laroux:93938383:Anthropology:Sophomore:Bubblegum*

lab46:~$ cat sample.db | grep Biology
Eric Vincent:1001119:Biology:Freshman:Lollipops*
Eric Vincent:1001119:Biology:Freshman:Lollipops*
Kris Warner:8383833:Biology:Senior:Mars Bar*

lab46:~$ cat sample.db | grep Biology | grep Lollipops
Eric Vincent:1001119:Biology:Freshman:Lollipops*
Eric Vincent:1001119:Biology:Freshman:Lollipops*

lab46:~$ echo "hello there:this:is:a:bunch of:text." | cut -d":" -f1
hello there
lab46:~$ echo "hello there:this:is:a:bunch of:text." | cut -d":" -f2
this
lab46:~$ echo "hello there:this:is:a:bunch of:text." | cut -d":" -f3
is
lab46:~$ echo "hello there:this:is:a:bunch of:text." | cut -d":" -f1,6 | sed -e 's/:/ /g'
hello there text.
lab46:~$ sort sample.db sorts alphabetically
Adelle Wilson:594893:Sociology:Junior:Ju-Ju Fish*
Alan Cox:40049300:Computer Science:Senior:Whoppers*
Alan Turing:40030333:Computer Science:Senior:Rock Candy*
Alan Wilson:22908948:Economics:Freshman:Whoppers*
Eric Vincent:1001119:Biology:Freshman:Lollipops*
Eric Vincent:1001119:Biology:Freshman:Lollipops*
Francois Laroux:93938383:Anthropology:Sophomore:Bubblegum*
Jill Ashley:9939392:Chemistry:Freshman:Warheads*
Jim Smith:105743:Economics:Sophomore:Lollipops*
John Doe:0000000:Unknown:Freshman:unknown*
Junior Mint:2228484:Liberal Arts:Junior:Junior Mints*
Kris Warner:8383833:Biology:Senior:Mars Bar*
Leet Haxzor:31337:Business:Sophomore:Gobstoppers*
Linus Torvalds:4432001:Computer Science:Senior:Snickers*
Matthew Green:439478:Philosophy:Junior:Necco Wafers*
Megan Tanner:372233:Physics:Junior:Zero Bar*
Sarah Billings:938389:Accounting:Freshman:Tic-Tacs*
name:sid:major:year:favorite candy*

lab46:~$ head -5 sample.db "print first 5 lines" tail does opposite prints last -n lines of file specified 
name:sid:major:year:favorite candy*
Jim Smith:105743:Economics:Sophomore:Lollipops*
Adelle Wilson:594893:Sociology:Junior:Ju-Ju Fish*
Sarah Billings:938389:Accounting:Freshman:Tic-Tacs*
Eric Vincent:1001119:Biology:Freshman:Lollipops*

Security (UNIX)
Definition

Security is ability to allow and/or deny access to information that is vital to any multi-user system.

Demonstration

To be able to change permissions, allow access for new directories created along with new files is just some of the basic but must be taken into account. below is a command line which will display the umask

lab46:~$ umask
0022
lab46:~$ touch newfile
lab46:~$ ls -l newfile
-rw-r--r-- 1 rmatsch lab46 0 Apr 21 12:18 newfile
lab46:~$

This means your default umask is set to this meaning that any files you make will have this minused the full permissions so a normal file full permission would be 666 but now when a new file is created thanks to umask the permissions on the file in octal are 644 which mean the owner can read and write to the file and everyone else can only read and same for group.

lab46:~$ mkdir newdirect
lab46:~$ ls -ld newdirect
drwxr-xr-x 2 rmatsch lab46 6 Apr 21 12:19 newdirect

full permission on a directory is 777 so 777 -22 = 755 which is show above with the owner having read write execute and group and world having only read and execute privileges.so umask is a very important thing to know if you are considering security of the system and users.

When you don't have access:

lab46:~$ cd /root
-bash: cd: /root: Permission denied
lab46:~$ chmod 077 newdirect "change newdirect's permissions to 077"
lab46:~$ cd newdirect
-bash: cd: newdirect: Permission denied
The unix shell (unix)
Definition

The Unix shell is a command-line interpreter that provides a user interface for Unix/linus operating systems. Users directly operate with the computer by entering commands execute, create, delete, and various other operation. There is no “ button clicking like windows computers”

Demonstration

At a command line interpreter such as bash or various other you can search through files, list files,create new files, copy files, delete files, make directories, and so on.Below is a demonstration of the various nothing i talked about just showing you that all task or “moving around the sytem is done through commands.

lab46:~$ ls
2              badname.tgz             newdirect
CCC.sh         bin                     phenny
CCCclasses.sh  class_notes             phenny.tar.bz2
Desktop        classlog.c              regex.html
Documents      count.c                 sample.db
Downloads      data                    spring2010-20091022.html
Maildir        fall2010-20100315.html  spring2010-20101113.html
Music          fall2010-20101113.html  spring2011-20101105.html
Pictures       fall2011-20110417.html  spring2011-20101113.html
Public         file                    spring2012-20111103.html
Templates      index.html              src
Videos         lab1                    stdout
archives       labD.sh                 winter2011-20101113.html
badname        motd
lab46:~$ cp count.c count.xxxxxxxxxxxxxx
lab46:~$ rm count.c
rm: remove regular file `count.c'? y
lab46:~$ mkdir newdirect2
lab46:~$ touch newfile
lab46:~$ ls
2              bin                     newfile
CCC.sh         class_notes             phenny
CCCclasses.sh  classlog.c              phenny.tar.bz2
Desktop        count.xxxxxxxxxxxxxx    regex.html
Documents      data                    sample.db
Downloads      fall2010-20100315.html  spring2010-20091022.html
Maildir        fall2010-20101113.html  spring2010-20101113.html
Music          fall2011-20110417.html  spring2011-20101105.html
Pictures       file                    spring2011-20101113.html
Public         index.html              spring2012-20111103.html
Templates      lab1                    src
Videos         labD.sh                 stdout
archives       motd                    winter2011-20101113.html
badname        newdirect
badname.tgz    newdirect2
lab46:~$ grep hey regex.html
<td NOSAVE><b><u><font size=+1>Objective:</font></u></b> To become familiar with the UNIX command line through exposure to some simple commands. The student will also be presented with traditional UNIX conventions they are expected to become familiar with and use throughout the semester.</td>
How have they changed?</td>

lab46:~$ cd ..
lab46:/home$ ls

bherrin2   dh018304  hshaikh     jsmit176  mdecker3  rmatsch     tp001498
bhuffner   dherman3  hwarren1    jstrong4  mdittler  rmoses      triley2
bkenne11   dlalond1  ian         jsulli34  mearley1  rnewman     ts004985
bobpauljr  dmay5     javery9     jtongue2  mgough    rpetzke1    wedge
bort       dmckinn2  jbaez       jtreacy   mguthri2  rraplee     wezlbot
bowlett1   dmurph14  jbamper     jtripp    mhenry9   rrichar8    wfischba
brian      dpadget8  jbarne13    jv001406  mkellogg  rsantia4    wknowle1
brobbin4   dparson3  jbesecke    jvanott1  mkelsey1  rshaw8      wroos
bstoll     dpotter8  jblaha      jwalrat2  mmatt     rthatch2    ystebbin
btaber2    dprutsm2  jblanch1    jwhitak3  mowens3   ryoung12    zlittle
bwheat     drobie2   jbrant      jwilli30  mp018526  sblake3     zmccann
bwilso23   ds000461  jbrizzee    jwilso39  mpage9    sc000826    zward
lab46:/home$ cd rmatsch
lab46:~$ cd src
lab46:~/src$ ls
Makefile  cprog  hello1  hello1.c  helloC  helloC.c  submit  unix
lab46:~/src$ cd unix
lab46:~/src/unix$ ls
arc.tar.gz    cs4.txt  cs9.txt  lab0.txt  lab5.txt  laba.txt
contact.info  cs5.txt  csA.txt  lab1.txt  lab6.txt  link.sh
cs1.txt       cs6.txt  csB.txt  lab2.txt  lab8.txt  scripting
cs2.txt       cs7.txt  csC.txt  lab3.txt  lab9.txt  shell
cs3.txt       cs8.txt  devel    lab4.txt  labC.txt  unix_html_stuff
lab46:~/src/unix$
Environment Variables
Definition

environment variables are significant and can be thought of in a sense to create the operating environment in which a process runs. environment variables set at login are valid for the duration of the session. Environment variables have UPPER CASE as opposed to lower case which are shell variables.

Demonstration
  USER (your login name)
  HOME (the path name of your home directory)
  HOST (the name of the computer you are using)
  ARCH (the architecture of the computers processor)
  DISPLAY (the name of the computer screen to display X windows)
  PRINTER (the default printer to send print jobs)
  PATH (the directories the shell should search to find a command)
lab46:~$ echo $HOME
/home/rmatsch
lab46:~$ echo $PATH
/home/rmatsch/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games
lab46:~$ echo $OSTYPE
linux-gnu
lab46:~$ echo $USER
rmatsch
lab46:~$ echo $home
lab46:~$
X window system
Definition

a software system which provides a basis for GUI's and has good input device capability for computers. basically it is used to build graphical user interfaces for unix like operating systems originally designed for network connection.

unix networking tools
Definition

tools used to gain networking information such as the host you are connected to and various other network data that may be useful.

Demonstration

some of the two most important networking tools i think are netstat, ping below are example of them to find information on dns server to see if packets or being sent and network information.

lab46:~$ ping localhost
PING localhost.localdomain (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost.localdomain (127.0.0.1): icmp_req=1 ttl=64 time=0.045 ms
64 bytes from localhost.localdomain (127.0.0.1): icmp_req=2 ttl=64 time=0.037 ms
64 bytes from localhost.localdomain (127.0.0.1): icmp_req=3 ttl=64 time=0.038 ms
64 bytes from localhost.localdomain (127.0.0.1): icmp_req=4 ttl=64 time=0.036 ms
^C
--- localhost.localdomain ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2997ms
rtt min/avg/max/mdev = 0.036/0.039/0.045/0.003 ms

netstat 
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 lab46.offbyone.la:60002 irc.offbyone.lan:ircd   ESTABLISHED
tcp        0      0 lab46.offbyone.lan:ssh  mobile-198-228-20:58895 ESTABLISHED
tcp        0      0 lab46.offbyone.la:47089 irc.offbyone.lan:ircd   ESTABLISHED


lab46:~$ netstat -ta
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 *:ssh                   *:*                     LISTEN
tcp        0      0 *:35801                 *:*                     LISTEN
tcp        0      0 *:nfs                   *:*                     LISTEN
tcp        0      0 *:3939                  *:*                     LISTEN
tcp        0      0 *:3333                  *:*                     LISTEN
tcp        0      0 lab46.offbyone.lan:5000 *:*                     LISTEN
tcp        0      0 lab46.offbyone.lan:5007 *:*                     LISTEN
tcp        0      0 *:59343                 *:*                     LISTEN
tcp        0      0 *:sunrpc                *:*                     LISTEN
tcp        0      0 *:csync2                *:*                     LISTEN
tcp        0      0 lab46.offbyone.lan:4242 *:*                     LISTEN
tcp        0      0 lab46.offbyone.la:60002 irc.offbyone.lan:ircd   ESTABLISHED
tcp        0      0 lab46.offbyone.lan:ssh  mobile-198-228-20:58895 ESTABLISHED
tcp        0      0 lab46.offbyone.la:47089 irc.offbyone.lan:ircd   ESTABLISHED
tcp        0      0 lab46.offbyone.la:47998 irc.offbyone.lan:ircd   ESTABLISHED
tcp        0      0 lab46.offbyone.la:42140 auth1.offbyone.lan:ldap ESTABLISHED
tcp        0      0 lab46.offbyone.la:45645 irc.offbyone.lan:ircd   ESTABLISHED
tcp        0      0 lab46.offbyone.la:58347 vm31.student.lab:ssh    ESTABLISHED
tcp        0      0 lab46.offbyone.la:44392 irc.offbyone.lan:ircd   ESTABLISHED
tcp        0      0 lab46.offbyone.la:51839 auth1.offbyone.lan:ldap ESTABLISHED
tcp        0      0 lab46.offbyone.la:47426 irc.offbyone.lan:ircd   ESTABLISHED
tcp        0      0 lab46.offbyone.la:33595 auth1.offbyone.lan:ldap ESTABLISHED
tcp        0      0 lab46.offbyone.la:44549 irc.offbyone.lan:ircd   ESTABLISHED


netstat -s |less

Ip:
    44800188 total packets received
    2 with invalid addresses
    280120 forwarded
    0 incoming packets discarded
    44488743 incoming packets delivered
    58096734 requests sent out
    7068 outgoing packets dropped
Icmp:
    10051 ICMP messages received
    28 input ICMP message failed.
    ICMP input histogram:
        destination unreachable: 9389
        echo requests: 250
        echo replies: 412
    9622 ICMP messages sent
    0 ICMP messages failed
    ICMP output histogram:
        destination unreachable: 659
        redirect: 7068
        echo request: 1645
        echo replies: 250
IcmpMsg:
        InType0: 412
        InType3: 9389
        InType8: 250
        OutType0: 250
        OutType3: 659
        OutType5: 7068
        OutType8: 1645
Tcp:
    80063 active connections openings
    38145 passive connection openings
    26780 failed connection attempts
    4252 connection resets received
    85 connections established
    44040550 segments received
    57184990 segments send out
    96026 segments retransmited
    0 bad segments received.
    30648 resets sent
Udp:
    388512 packets received
Compiler, Assembler, Linker, Loader
Definition
Demonstration

Demonstration 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);
}

Alternatively (or additionally), 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$ 
Source Code, Object Code, Binary Code, Library
Definition

source code is code written by a programmer in a text editor, object code is the source code compiled and ready to be linked to the binary code which is the binary executable the processor reads. library can be thought of as a place where header files are located.

Demonstration
lab46:~$ vi hello.c
lab46:~$ file hello.c
hello.c: ASCII C program text
lab46:~$ gcc -c hello.c
lab46:~$ ls
hello.c
hello.o
lab46:~$ file hello.o
hello.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
lab46:~$ gcc -o helo hello.o
lab46:~$ file helo
helo: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, not stripped
lab46:~$ file hello.o
hello.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
lab46:~$ file hello.c
hello.c: ASCII C program text

unix Objective

unix Objective

students should be able to set permissions on file directories ad be able to filter text using utilities

Definition

the objective entails using reg expression cut(1),tr(1), and many more tools to filter text and be familiar with unix security.

Method

Tell students to find what the default file and directory access is set to and how to change that default permission using umask and have an understanding of what is happening. ask students to search through a document and put the information into a useable manner by filtering the document or database. students should also be asked to change the permissions using chmod utility and demonstrate a clear understanding in permissions and security

Measurement
lab46:~$ umask
0022
lab46:~$ touch file
lab46:~$ ls -l file
-rwxr-xr-x 1 rmatsch lab46 7481 Apr 21 16:21 file
lab46:~$ umask 000
lab46:~$ touch file2
lab46:~$ ls -l file2
-rw-rw-rw- 1 rmatsch lab46 0 Apr 21 16:21 file2
lab46:~$ umask 22
lab46:~$ mkdir newd
lab46:~$ ls -ld
drwx-----x 30 rmatsch lab46 4096 Apr 21 16:23 .
lab46:~$ ls -ld newd
drwxr-xr-x 2 rmatsch lab46 6 Apr 21 16:23 newd
lab46:~$ umask 22
lab46:~$ chmd
-bash: chmd: command not found
lab46:~$ chmod 777 newd
lab46:~$ ls -ld newd
drwxrwxrwx 2 rmatsch lab46 6 Apr 21 16:23 newd
lab46:~$

1 is execute read is 4 and write is 2

Analysis

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

  • How did you do?very good
  • Is there room for improvement?yes
  • Could the measurement process be enhanced to be more effective?yes
  • Do you think this enhancement would be efficient to employ?yes
  • Could the course objective be altered to be more applicable? How would you alter it?no

Experiments

Experiment 7

Question

what will happen if you remove #ndef #define #endif from header files and re compile

Resources

Class notes

Hypothesis

I think the program will compile with out any problems.

Experiment

take a c++ program with multiple header files and remove the #ndef statements and see what happens.

Data

it compiled with out the statements.

Analysis,Conclusion

Based on the data collected:

  • Was your hypothesis correct? yes my hypothesis was correct and i was able to compile.
  • Was your hypothesis not applicable?yes

upon further investigation in small problems probably wont matter so much but with many header files and larger programs this could be a big plus to have.

Experiment 8

Question

can kids touch there parents private parts (C++ inheritance)

Resources

Mathew hass

Hypothesis

no kids to parent relationships cannot touch there parents private parts because then it would not be a private class if the kid had a friend and then third parties could touch the parents private parts which is not good for security.

Experiment

develop a program and set certain variables to private class and then try to access these variables via a kid of the parent.

Analysis

Based on the data collected:

  • Was your hypothesis correct?yes
  • Was your hypothesis not applicable?yes
  • Is there more going on than you originally thought? yes(shortcomings in hypothesis)
  • What shortcomings might there be in your experiment? taking into account friends

Conclusions

C++ is great for code management and for security purposes as data access..

Retest 3

State Experiment

Resources

Evaluate their resources and commentary. Answer the following questions:

  • Do you feel the given resources are adequate in providing sufficient background information?
  • Are there additional resources you've found that you can add to the resources list?
  • Does the original experimenter appear to have obtained a necessary fundamental understanding of the concepts leading up to their stated experiment?
  • If you find a deviation in opinion, state why you think this might exist.

Hypothesis

What is the use of \n and to what effect does it have if in a simple program designed to print “hello world” if: 1. it exists.

2. it does not I feel their hypothesis is adequate in capturing the essence of what they're trying to discover. and there is no adjustments i would make.

Experiment

Follow the steps given to recreate the original experiment. Answer the following questions:

  • Are the instructions correct in successfully achieving the results?

there is not to many directions to establish how to do it if i did not have any knowledge of C I feel there room for improvement in the experiment instructions/description such as a small snip of code.

  • Would you make any alterations to the structure of the experiment to yield better results?

no it is a simple experiment so there structure would do.

Data

#include <stdio.h>
int main()
{
        printf("hello, world\n");
        printf("hello,\n world");

return(0);
}
lab46:~$ gcc -o hello hello.c
lab46:~$ ./hello
hello, world
hello,
world

Analysis

Answer the following:

  • Does the data seem in-line with the published data from the original author?

Yes the data seems in-line with the author

  • Can you explain any deviations?

There is no deviations.

  • Is the stated hypothesis adequate?

Yes the stated hypothesis is adequate.

Conclusions

Answer the following:

  • What conclusions can you make based on performing the experiment?

\n will make a new line

  • Do you feel the experiment was adequate in obtaining a further understanding of a concept? yes
  • Does the original author appear to have gotten some value out of performing the experiment?yes

Good job experiment was done well.

opus/spring2012/rmatsch/start.txt · Last modified: 2012/08/19 16:24 by 127.0.0.1