Table of Contents

Derek Girardi's fall 2011 Opus

It's Amazing

Introduction

Hi im derek. I plan to be a programmer and trying get my masters in programming (computer science). On the side i do play drums. I play in a band, drum corp and i hope to minor in music as well. I also play french horn, piano and other random instruments. I learned it all in band and from my mom. We are a very musical family. Basically i just like to have fun with whatever im doing, so yea. I am the dataking and you can not beat me. If you try, i will beat you down and make sure you never go above me. I play xbox and any games i want, especially skyrim. I can waste hours of my life on this game. And i also play lots of call of duty, i dont care what anyone says. I drink a lot of mountain dew and i like candy, dont judge me. Nyan cat is a champion of the world, if you dont know who that is, go away. Other then that, dont bother me when im doing work or else the data king will have you removed with the simple phrase “Begone peasant!” Thank you :)

Part 1

Entries

September 1, 2011

Today we have learned some simple commands to navigate through linux. The CD was brought up and that by default takes us to our home directory. But when used with a directory name it will take us there. Also learned how to change permissions on each file. Its kinda confusing how the numbers work but i believe i can pick it up pretty fast. Also learned other simple commands like ls and pwd and who. ls list files in a directory, pwd tells you where you are and who tells you who you are.So we basically just learned some basics and concepts of how files work. Also set up class chat. In cprog I have read chapter one of “the C programming language”. I learned simple things like printf to say hello, and showing variables and arithmetic. I wrote one or 2 simple programs but that is about it so far. Nothing seems to difficult so far

September 8, 2011

In linux we focused mainly on using the text editor Vi. It is moded text editor unlike most. Both the command and insert mode are completely separated from each other. So instead of using nano, we have learned to use this. There are various commands to do number of things. You can jump words, or letters or sentences and so much more. It is a confusing editor i will agree but if i play with it some more i believe i can get better with it. practice makes perfect. But pretty much with vi i just need to play to figure out what commands i truly need to know and what i could use. Other than that, this class is going well so far with some new commands like date and cal. Can get really general or specific. In cprog i have read chapter 2 of the book and it talks about declarations,operators, conversions and etc. I am going to re-read this section i believe because i am in a rut with it and i would like to get this down so i can start projects here soon.

September 15, 2011

In linux we have learned about process id's (Pid). they are basically a small id for any process that happens to be running. So anything you are doing at that moment has a pid. With that you can go in a maniupulate it in some way. Thats when we learned the kill command. We take the pid of the process we want to kill and we just kill it. They are numerous kill options but we prefer kill -9. We also learned that there is such things as zombies. Expected zombies we can take care of but an unexpected zombie is something we do not want period. so we learned how to make expected zombies, find processes with any specifics and a little more on vi and a similar editor that i cant remember. In cprog i have chapter 3 but likewise i am going to re read it. The concepts are kind difficult but im just going to take a day and do sample programs till i understand fully or well enough.

September 22, 2011

In linux today we learned shell scripting. You basically run the system from the outside instead of the inside. We wrote some simple scripts like one will ask for our name and say a message. Then another one asks for a password. either the password was in the script or it called another file with the password we wanted. We learned what we needed to do, what means what like # stands for a comment. #! this is a shhh bang!And we made them executable with a new way of changing permissions. He gave us one more program which took any files in a directory and got rid of any extensions and made them all just regular files, no extensions. Cprog i have moved on to chapter 4 and its about functions mainly. I understand functions so its no problem but i believe at this point, i can start doing projects. I still need to go over a few chapters though, some things are still a little iffy for me.

CPROG Topics

Standard I/O (STDIO, STDOUT, STDERR)

In standard I/O you have STDIO, STDOUT and STDERR. STDIO is you communications stream, your user input. It is attached to your keyboard and whatever you type in, the input will read it and take it and store it in its memory. STDOUT is attached to your command window and it will print out data onto to your display window. STDERR this is also attached to the command window and it is there to display error messages when things go wrong.

Header files

Header files are files that allow programmers to seperate certain elements into reusable files. Header files commonly contain forward declarations of classes, subroutines, variables, and other identifiers. If programmers wish to use more than one source file they can put it into one header file, and it can be used throughout each source you wish to use these reusable files.

Arithmetic

There is a lot of arithmetic going on in the language of see but your most common is conversion arithemetic. Most C operators perform type conversions to bring the operands of an expression to a common type or to extend short values to the integer size used in machine operations.

float   fVal;
double  dVal;
int   iVal;
unsigned long ulVal;

dVal = iVal * ulVal; /* iVal converted to unsigned long
                      * Uses step 4.
                      * Result of multiplication converted to double 
                      */
dVal = ulVal + fVal; /* ulVal converted to float
                      * Uses step 3.
                      * Result of addition converted to double 
                      */ 

Logic and operators

There are a lot of operators that can be used in the C world. You have logical operators such as AND, OR and NOT. These are choice operators like if you use AND both must be true in order for the code of program to work. With an OR one or both must be true to work. And NOT Just says you can not be eqaul to this and it will work. You basic opartors such ass addition, subtraction, multiplication and division. These operators are there so you can complete the logic needed to fullfill your program. Without the operators, you could not do the program logic.

Scope

This is where a program can or cannot touch. It has the global scope, where variables can be declared for the entire program to see and use. Then you have a local scope where variables are declared in a function and can only been seen and used with in that function.

global:

#include <stdio.h>
 
int ginteger;
float globalfloat;
 
int main ()
{
  exit (0);
}

Local:

#include <stdio.h>
 
int main()
{
  int hi;
  float a, b, c;
 
  exit (0);
}

Array

This is a collection of same type of elements. it can hold more than one variable and can be used to organize numbers, sort, count or many other uses.

<data type> array_name[size_of_array];

You can initialize the array once you declare it if you know what you want to go in there but if not, you can put values into there throughout the program.

Variables

Variables are the things are created along with a data type. When you use a dat type such as int or char, you assigned it a variable. So you will have something as simple as “int = 6” or something as that. The int is being declared to a variable of 6.

“String”, Format/Formatted Text String

Formatting a string in a program is easy when you use the function printf(). The format string specifies a method for rendering an arbitrary number of varied data type parameter(s) into a string.

printf("Color %s, number1 %d, number2 %05d, hex %x, float %5.2f, unsigned value %u.\n",
        "red", 123456, 89, 255, 3.14159, 250);

basically when the printf function is used, it can print out whatever character you use into one string that will be displayed onto your screen.

File Access (Read, Write, Append)

In order to do file access you need the function fopen(). Now this function will open up what is inside the file. You can also write and append to this. To append to the file you need the fopen() with “a” permission and to write to a file you need fopen with “w”. Now these are just the simple things you can accomplish with fopen.

#include <stdio.h>

int main(void)
{
    char buffer[256];
    FILE * myfile;
	
    myfile = fopen("some.txt","r");
	
    while (!feof(myfile))
    {
        fgets(buffer,256,myfile);
        printf("%s",buffer);
    }
	
    fclose(myfile);
    
    return 0;
}

Functions

Every language has a function either it is called subroutine or procedure, there is a function. In C it is called a function. A function is used to do seprate logic operations outside of the main so its not so cluttered. Then in the main you can call the function and use it like you would regular functions like printf(). They can either have a return value or no return value, depending on what your program is asking for.

double power(double val, unsigned pow)
{       double ret_val = 1.0;
        unsigned i;

        for(i = 0; i < pow; i++)
                ret_val *= val;

        return(ret_val);
}

Parameters (Pass by: Value, Address, Reference)

These parameters can be of any type, data types that have been defined by the programmer. As long as the C compiler can locate the types (i.e. they are in scope) at compile time, then any can be used. A parameter can be passed by reference or by value. When passed by reference it can be altered inside the function. When it is passed by value it can not, only a copy of the value is passed on. Depending on how your program is, you can choose one or the other that fits it best.

Return Types

The return type of a function establishes the size and type of the value returned by the function. This is basically what kind of datatype you will be receiving from the program. You have many types like int, typedef, void, char, short, float, double and many other things. All these are return types and can be used in just about any program language.

UNIX Topics

Regular

Regular files in linux are just common files in the linux system. They basically hold data and text and even binary data. regular files hold a dash next to the permissions to show that it is a regular file. They are also white, white is the color of regular.

Ls(Listing)

The ls command lets you list what files and/or directories are located in your current directory. It can be listed in many different ways and it can either just tell you the name or give you more detailed information.

lab46:~$ ls
Maildir  bin     contact.info.save  destructo.sh  hey  hi.c           lab1a.text  newdirectory  public_html      soaringeagle1.sh  tmp
a.out    closet  data               hello.c       hi   killerwasp.sh  motd        pss           soaringeagle.sh  src
lab46:~$ 

Directory

A directory is a blue file you will see on your linux terminal, in the home. Now these type of files hold even more files that the system runs or they just can be extra files that you want in a common place. Like you will want data1, data2, data3 and data4 all in one place. So you will place it in a directory called “DATA” and that will be a blue file that can now hold those and anything else you want to stick in there.

Special

Special files are also known as device files. Two kinds exist: buffered device files and unbuffered device files. The buffered special device files are called block device files; the unbuffered ones are the character device files.

So links are called symbolic links as well. And basically you “link” two files together. When you do this you use the “>” to give an absolute path you want the file linked to. So i can take my home directory and link it directly to another directly or whatever you need to do. Links bring files together easily.

Permissions

As a user you have file permissions. You have all full permissions in your home directory mainly because they are your files. Now you can have permissions over other things as long as you are allowed to have these permissions or you are the superuser and can do what you want. Now in order to change the permission of a file you can use chmod. now yo have a rwx for user, group and other. User is what permissions you have, group is the permissions others have and other are just system permissions. Now with chmod you can do 2 things either change it with letters or numbers. you can do something like 474 or do like -x, -r, -rw, -. or whatever combination. here is an example of what i do:

lab46:~$ touch jesus
lab46:~$ chmod -x jesus
lab46:~$ ls
Cexetension.tgz   a.out              invaderzim    public_html
Desktop           badname            irc           puzzlebox
Documents         badname.tgz        jesus         puzzlepaper
Downloads         bin                lab1a.text    regularexpressions
FilelistforOPTAR  candy              motd          scripts
Maildir           classlog12         networkcmds   spring2012-20111103.html
Music             contact.info.save  newdirectory  src
Nyan Cat.wav      courses            out           test
Public            data               outfile       test2
Schedulecut       dl                 output        tmp
Templates         hiopus             pgm2ps        unixprog
Videos            in                 pss           wildcards
lab46:~$

Ownership

To change the ownership of a file you use chown. You can use this to make a file used by user only, or by group only or a mixture of the 2. If only an owner (a user name or numeric user ID) is given, that user is made the owner of each given file, and the files' group is not changed. If the owner is followed by a colon and a group name (or numeric group ID), with no spaces between them, the group ownership of the files is changed as well.

Viewing

In linux you can easily view a file with the command of cat and less. Cat looks in a file and displays the data onto the command line prompt for you to see. Now the less is there if the data is like really huge, it makes it so it is much easier to read on the screen. Just makes it better. Here is an example:

lab46:~$ ls
Cexetension.tgz   badname            jesus         regularexpressions
Desktop           badname.tgz        lab1a.text    scottysnumber
Documents         bin                motd          scripts
Downloads         candy              networkcmds   spring2012-20111103.html
FilelistforOPTAR  classlog12         newdirectory  src
Maildir           contact.info.save  out           test
Music             courses            outfile       test2
Nyan Cat.wav      data               output        tmp
Public            dl                 pgm2ps        unixprog
Schedulecut       hiopus             pss           wildcards
Templates         in                 public_html
Videos            invaderzim         puzzlebox
a.out             irc                puzzlepaper
lab46:~$ cat invaderzim
yep... DIARRHEA
lab46:~$

Insert Mode

The Insert mode is what you'll work in most of the time. You use it to make changes in an open file. Enter the Insert mode by pressing the I key. Newer Vi versions will display the word “INSERT' on the bottom line while you're in Insert mode. Here is an example real quick:

  1
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
-- INSERT --                                                  0,1           All

Now when in here you mainly just type out what you want and when you are to finish off this editing hit the esc key to enter back into command mode, where most commands to like save will be held.

Command Mode

The program opens in the Command mode, which is used for cursor movements, delete, cut, copy, paste, and saving changes.

  1
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
                                                              0,0-1         All

Looks very similar to insert mode just with the big word, insert. This is where you will execute your commands such as save and delete and start a new line, etc. You will have commands like ”:wq“ for save and quit or “q!” for quit without saving. As you learn this more and use it more and just play with it, you will learn a lot about what commands are in this. Not even i know how many commands are on this thing, as a student i am still learning. there are man pages though do not forget. here are some commands you can find on the man page:

Press Key(s):* Function:

I Insert text before the cursor

A Insert text after the cursor

: Switch to ex mode

$ Go to last place on the line

W Next word

B Previous word

Shift-G Last line of the file

20 Shift-G Go to line 20

Y Copy. (Note: Y3W = copy 3 words; Y3J = copy 4 lines.)

P Paste

D Cut

X Delete character under the cursor

Extended Command Mode

The extended or ex mode is similar to an independent line-oriented editor that can be used for various simple and more complex tasks. The commands you would have in here are:

:q – quit without saving

:q! – quit forcefully without saving

:w – save

:wq – save & quit

:wq! – save & quit forcefully

:sh – provides temporary shell

:se nu – setting line numbers

:se nonu – removing line numbers

:84(enter) – goes to line number 84

as you see to enter the extended mode you use the colon and gives you extra commands then the simple ones found in command mode.

The UNIX shell

The UNIX shell is a place where the user enters commands to the command line and scripts within this shell are executed by programs in files. Now the shell and unix itself are files, everything is a file. You can write shell scripts to customize how you want the shell to act and look like. Now the shell we work in is the C shell. It is written in the language of C and is highly compatible with the language source code. So you can easily program on this shell if you wanted to. The shell is basically where you work with the files and manipulate them. The shell is just there to hide the kernel, the heart of the operating system. The shell is here to make the lower level systems easier to manipulate and use.

CPROG Objectives

Objective 1

know the difference between structures and classes. A struct has members that are public by default and can be inherited by public as well, while a class is private by default and is inherited privately as well.

Method

I will show this program through a sample program that should hopefully prove the difference of struct and classes.

Measurement

#include <stdio.h>
class A
{
   public:
      int a;
};
 
struct B > A { };
 
struct C
{
      int c;
}
 
class D > C { };
 
int main()
{
   B b;
   D d;
   b.a = 1;
   d.c = 2;
}

Analysis

reflecting upon objective

  • How did you do? I think i did ok i believe i can improve on this more because i haven't fully grasp the concept of this yet.
  • Room for improvement? There is always room for improvement.
  • Could the measurement process be enhanced to be more effective? yes it could be used in a example of an everyday program or it could be more user friendly.
  • Do you think this enhancement would be efficient to employ? No it is only an example however it could be efficient to be used as a template.
  • Could the course objective be altered to be more applicable? How would you alter it? Yes it could. I would alter it by showing it used into an actual program and showing the output of it. Then take the section of the compiled code and store it somewhere so if someone needs something similar to this i would just access it and use it.

UNIX Objectives

Objective 1

Familiarity with the structure of UNIX systems. This is basically stating what the unix system is and in its entirety, its a hierarchy of files. Everything has a file of some sort and is run through files.

Method

I will use commands on the command line to show the different files and how you can go deeper and deeper into files, just showing how its all connected in some way.

Measurement

lab46:~$ cd ..
lab46:/home$ cd .
lab46:/home$ cd ..
lab46:/$ ls
bin   etc         lib    lost+found  opt   sbin     sys  var
boot  home        lib32  media       proc  selinux  tmp  vmlinuz
dev   initrd.img  lib64  mnt         root  srv      usr
lab46:/$ cd
lab46:~$ ls
Maildir  contact.info.save  hi             lab1a.text    soaringeagle.sh
a.out    data               hi.c           motd          soaringeagle1.sh
bin      destructo.sh       in             newdirectory  src
botopen  hello.c            irc            pss           tmp
closet   hey                killerwasp.sh  public_html
lab46:~$ cd
lab46:~$ cd src
lab46:~/src$ ls
Makefile  cprog  discrete  submit  unix
lab46:~/src$ 

Analysis

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

  • How did you do? I did good on stating the objective
  • Room for improvement? No i believe there is not but there could always be improvement.
  • Could the measurement process be enhanced to be more effective? i could show it in a better format then i might have done
  • Do you think this enhancement would be efficient to employ? No it should be fine on its own
  • Could the course objective be altered to be more applicable? How would you alter it? No it could not

Experiments

Experiment 1

Question

What would happen if i moved the tmp file into my own home directory?

Resources

My resources for this will be for class, there is no need for further information on it

Hypothesis

First my objective is to see why the tmp is highlighted in the root directory. We are going to see what happens when i move it. In its original directory it is highlighted for some reason and im going to see if it disappears when i move it. I believe it being highlighted will disappear when its moved over to my directory.

Experiment

Im going to show the tmp file. then show the commands im going to use to move it and/or copy it over. and show it within my home directory.

Data

lab46:~$ cd ..
lab46:/home$ cd ..
lab46:/$ ls
bin   etc         lib    lost+found  opt   sbin     sys  var
boot  home        lib32  media       proc  selinux  tmp  vmlinuz
dev   initrd.img  lib64  mnt         root  srv      usr
lab46:/$ mv tmp home
mv: cannot create directory `home/tmp': Permission denied
lab46:/$ cp tmp tmp1
cp: omitting directory `tmp'
lab46:/$ ls
bin   etc         lib    lost+found  opt   sbin     sys  var
boot  home        lib32  media       proc  selinux  tmp  vmlinuz
dev   initrd.img  lib64  mnt         root  srv      usr
lab46:/$ cd tmp
lab46:/tmp$ ls
fishd.log.cforman   fishd.socket.cforman   hsperfdata_bh011695  img--03883.asc
fishd.log.critten1  fishd.socket.critten1  hsperfdata_bstoll    lost+found
fishd.log.root      fishd.socket.root      hsperfdata_dschoeff  script
fishd.log.vcordes1  fishd.socket.vcordes1  hsperfdata_mgough
fishd.log.wedge     fishd.socket.wedge     hsperfdata_rmoses
lab46:/tmp$ 

Analysis

  • was your hypothesis correct? No it was not
  • was your hypothesis not applicable? It was applicable buti could not complete the task
  • is there more going on than you originally thought? (shortcomings in hypothesis) No there is not more, i am just denied permission to what i originally wanted to do so nothing could be done.
  • what shortcomings might there be in your experiment? permissions not in my control
  • what shortcomings might there be in your data? there is none

Conclusions

The tmp directory in the root directory of the system cannot not be moved or copied to another directory. It hs files that will create when they are needed and be deleted. The reason its highlighted, to my understanding, is that it cannot be touched by any users unless you are admin on the server. so in the end, i am unable to change or move any files that have that kind of highlighting.

Experiment 2

Question

Can you kill someone elses process?

Resources

I will be usuing information i have learned in class.

Hypothesis

I believe if the permissions allow it, i can kill any process on anyone's terminal.

All i need to do is find the processes using the ps aux command and it should show everyones process id's, then once i find them all i need to do is kill it with the correct pid.

Experiment

I am going to try to show through the command line at home. if i can not i can explain what will happen.

Data

lab46:~$ ps aux | grep SCREEN
bewanyk   1052  0.0  0.0  62752   868 ?        SNs  Sep16   0:01 SCREEN
dschoeff  1151  0.0  0.0  62872  1020 ?        SNs  Sep16   0:01 SCREEN
abrunda1  1195  0.0  0.0  62636   616 ?        SNs  Sep16   0:01 SCREEN
bh011695  1200  0.0  0.0  62744  1008 ?        SNs  Sep16   0:02 SCREEN irssi
mgough    1283  0.0  0.1  62720  1100 ?        SNs  Sep16   0:02 SCREEN
mowens3   1467  0.0  0.0  62212   528 ?        SNs  Sep16   0:00 SCREEN
tgalpin2  1945  0.0  0.0  62476   476 ?        SNs  Sep16   0:00 SCREEN
mshort3   2112  0.0  0.0  62344   520 ?        SNs  Sep16   0:01 SCREEN
lburzyns  2329  0.0  0.0  62212   224 ?        SNs  Sep22   0:00 SCREEN
kkrauss1  2616  0.0  0.1  62796  1136 ?        SNs  Sep16   0:03 SCREEN
qclark    3171  0.0  0.0  63276    28 ?        SNs  Sep29   0:00 SCREEN
asowers   3454  0.0  0.0  62628   540 ?        SNs  Sep16   0:00 SCREEN
afassett  7756  0.0  0.0  62212   336 ?        SNs  Sep18   0:00 SCREEN
vcordes1  7769  0.0  0.0  62344   164 ?        SNs  Sep28   0:00 SCREEN -a
syang     7902  0.0  0.0  62740   196 ?        SNs  Sep28   0:00 SCREEN
qclark    8037  0.0  0.0  62344    12 ?        SNs  16:28   0:00 SCREEN
asowers  10361  0.0  0.0  62212   160 ?        SNs  Sep29   0:00 SCREEN
dherman3 11940  0.0  0.0  62212   220 ?        SNs  Sep27   0:00 SCREEN
kreed11  12067  0.0  0.0  62516   336 ?        SNs  Sep22   0:00 SCREEN
sweller5 14219  0.0  0.0  62204   172 ?        SNs  13:22   0:00 SCREEN
jhammo13 18902  0.0  0.0  62212   152 ?        SNs  Sep19   0:00 SCREEN
dgirard3 18923  0.0  0.0  10088   868 pts/66   SN+  23:37   0:00 grep SCREEN
kinney   19066  0.0  0.0  62204   408 ?        SNs  Sep19   0:01 SCREEN
mtaft4   20336  0.0  0.0  62212   288 ?        SNs  Sep19   0:00 SCREEN
nsano    22657  0.0  0.0  62344   420 ?        SNs  Sep20   0:00 SCREEN
jjohns43 22802  0.0  0.0  62488   664 ?        SNs  Sep20   0:02 SCREEN
ccaccia  23078  0.0  0.0  63288  1032 ?        SNs  Sep20   0:13 SCREEN
lgottsha 23923  0.0  0.0  62512   612 ?        SNs  Sep20   0:00 SCREEN -a
dgirard3 24243  0.0  0.0  62212   320 ?        SNs  Sep20   0:00 SCREEN
cforman  24589  0.0  0.0  62344   484 ?        SNs  Sep20   0:00 SCREEN
csteve16 25457  0.0  0.0  62212   156 ?        SNs  14:40   0:00 SCREEN
drobie2  27767  0.0  0.0  62360   868 ?        SNs  Sep21   0:00 SCREEN
critten1 27783  0.0  0.0  62212   272 ?        SNs  Sep20   0:00 SCREEN
acanfie1 27943  0.0  0.0  62580   660 ?        SNs  Sep18   0:01 SCREEN -l
rlott    28620  0.0  0.1  63300  1316 ?        SNs  Sep22   0:00 SCREEN
jr018429 29483  0.0  0.0  62212   292 ?        SNs  Sep18   0:00 SCREEN
swilli31 30392  0.0  0.0  62212   168 ?        SNs  Sep29   0:00 SCREEN
lab46:~$ kill -9 25457
-bash: kill: (25457) - Operation not permitted
lab46:~$ 

i used the grep command to find process only with SCREEN in the name

Analysis

Based on the data collected: I cannot kill someones terminal using a simple kill command

  • was your hypothesis correct? No it was not
  • was your hypothesis not applicable? Yes it is, if i can change permissions then the hypothesis will become true
  • is there more going on than you originally thought? (shortcomings in hypothesis) there are permissions restricting my access
  • what shortcomings might there be in your experiment? It might be cause im working from home but that is highly not the case.
  • what shortcomings might there be in your data? none, just permissions

Conclusions

Basically in the end, one can not simply kill someone elses terminal or process. You can only kill your own or if someone changes their permissions on it, then it can be done. But other than that, nothing will change.

Experiment 3

Question

Can you make a script to run simple commands?

Resources

Im just going to use info from class.

Hypothesis

I believe with the right script you can easily issue a command from a script. A script is a program that can run outside the shell, looking down it. It can control what happens with the right coding and other little commands.

Experiment

I will show my script on here then show in the terminal running.

Data

lab46:~$ vi soaringeagle1.sh
lab46:~$ vi
lab46:~$ vi exper
lab46:~$ vi soaringeagle1.sh
lab46:~$ vi exper
lab46:~$ ./exper
-bash: ./exper: Permission denied
lab46:~$ vi exper
lab46:~$ ./exper
-bash: ./exper: Permission denied
lab46:~$ chmod u+x exper
lab46:~$ ./exper
-bash: ./exper: /bin/bas: bad interpreter: No such file or directory
lab46:~$ vi exper
lab46:~$ ./exper
./exper: line 2: Maildir: command not found
./exper: line 3: return: can only `return' from a function or sourced script
lab46:~$ vi exper
lab46:~$ ./exper
./exper: line 2: Maildir: command not found
lab46:~$ 

My script was a simple #!/bin/bash with a expansion on the ls command connecting to the home directory. However it is saying i have no permissions to do this.

Analysis

Based on the data collected:

  • was your hypothesis correct? No it was not
  • was your hypothesis not applicable? No it is not, it cannot replace what it can do already
  • is there more going on than you originally thought? (shortcomings in hypothesis) Yes. The command is already preset to what it is suppose to do so when i try to write a script to write the same thing, it wont allow it.
  • what shortcomings might there be in your experiment? the script may have been written wrong or the command doesnt want me to expand it
  • what shortcomings might there be in your data? No i knew exactly what was happening

Conclusions

In the end, i believe my script is wrong. It was a simple script but it may have been written wrong, but regardless what i took from this is that you shouldnt make a script to run a simple command when you can just type the 2 letters. But i believe there is a way to do this so i do believe this was a fail experiment but can deffinitly be looked at again in the future

Part 2

Entries

October 6, 2011

This week we learned some new things with regular expressions. Normally we would use a command like cut or grep to pick apart data and choose what we want to show. But with the regular expressions we were able to be even more precise in a more concise manner as well. They are a little hard to grasp because the concepts are kind of obscure, but for the most part i understand how they work. I just need to work with them more in my shell scripting or just in general like in my programs as well. We also did a script that will extract the data from our opus. It takes the total score you can get, the score you got and what percentage you recieve. We wrote that and added more on like cutting off the many decimal points after or similar stuff. We used some regular expressions in it as well which is really confusing but if i pick it apart piece by piece i can understand it. For C i have read more of the book and did a few practice programs from the book and the excercises it gives us. I have yet to start the dataypes project but i should have that done this weekend and i have another idea already for a new project. But other than that, i believe i am getting a grasp on the c language, still a little weird on arrays and calling a function. I understand what they are but i am a little confused on how they work at times but i will get it eventually.

October 13, 2011

This week we did more with regular expressions. We played around with that and used them in a script to become more familiar with them, we also learned wildcards. They are similar to expressions but wildcards are for files, not text. So we can manipulate files with them, not text. we wrote some scripts with the regular expressions in them and we also tried to go through the dictionary finding words only using regular expressions. That was interesting but fun, it made it a lot easier to use when we put it to a simple concept like words in a dictionary. We also just messed around with scripts this week by making one that did binary conversion, it only went to a certain number but it did its job. We learned that linux had its own area for math and it was implemented within the script. In c, i have been reading more of the book however i have not really worked on any projects or exercises. I know i must have 8 or possibly more projects done by the end of the month, i will do my best to finish them. In the meantime, i have been reading and learning however i know i must do some kind of programming to fully reinforce the syntax and logic i must use.

October 20, 2011

This week in linux we played around a little bit with the c language. The class did the first and best program that i will ever write which is the “hello, world” program. It was a simple program but it got the point across on how to write a c language program. then we used linux terminal to compile and execute our programs. After that we got into a little bit more complex programs and played around with them and made our programs work with linux. basically this week was a little introduction to the language for the unix/linux class. For C i have yet to really start anything, i have procrastinated horribly and have not done anything at all this week. I have read when i had time and a little programming aside from the linux class but not enough to truly say i have done work. This coming month i will be sure to get work done.

October 27, 2011

This week was an easy week for classes. This week was catch up on work week, so with the time i had i worked on doing projects. I got up to 4 projects done, one was not documented yet but i will do that once i get the chance. So for the class of unix i have 4 projects and c/c++ i still i have only one done. I really need to get it dont but it is hard with it being online because it constantly sits in the back of my mind and not in the front with the other classes so i become very forgetful, i will step up my game this month and get things done.

cprog Topics

Header Files

header files are files that seperate certain elements from the source code into a reusable file. They contain things like identifiers, classes, subroutines, and other identifiers. A programmer will include this file so that can use standard identifiers to help implement their code easier.

 1 #include <stdio.h>   // This is the header file for the standard library of input and output. So use things like printf and scanf.
  2 #include <math.h>
  3 int main()
  4 {
  5 unsigned short int bob=0;
  6 signed short int jim=0;
  7 printf("before , jim is %hd\n", jim);
  8 jim=pow(2, sizeof(jim)*8);
  9 printf("after, jim is %hd\n", jim);
 10 printf("jim is %d bytes\n", sizeof(jim));
 11 return(0);
 12 }

Pointers

This is a data type that “points” directly to another value stored somewhere in the computer memory using its address. The symbol for a pointer is *. Pointers are simply a indexed array arithmetic, so if you know one it is not too hard to learn the other. here is an example of a pointer:

int a = 5;
int *ptr = NULL;
 
ptr = &a;

This pointer is equal to a null value and points to the address of a.

Multi-Dimensional Array

Multi-dimensional arrays are like arrays within arrays. They have rows and columns with elements to fill them all. You can have a table like structure in it (rectangular to be exact) and pick and choose where to look within the array. you can do this with referenced pointers and thats what would be more commonly used. With this you can put the number of days in a month, all into one place. Below is how it would be shown:

int array2d[ROWS][COLUMNS];

Where the row and column is, thats where you specify your location in the array.

Type Casting

Typecasting is making a variable of one type, such as an int, act like another type, a char, for one single operation. To typecast something, simply put the type of variable you want the actual variable to act as inside parentheses in front of the actual variable. (char)a will make 'a' function as a char.

#include <stdio.h> 

using namespace std;

int main()       
{
  printf (char)65 <<"\n"; 
  // The (char) is a typecast, telling the computer to interpret the 65 as a
  //  character, not as a number.  It is going to give the character output of 
  //  the equivalent of the number 65 (It should be the letter A for ASCII).
  scanf();
}

Selection Structures

The ability to change the flow of program execution. It is achieve by establishing the truth or falsity of an expression (condition). This is done by statements like if, switch or case/file. An if statement asks the user or a process a question of some sort, and it is either the truth or false and depending on where it goes is how the program runs.

This is if:

#include <stdio.h>

int main()
{
  int choice;
  printf("Choose an option: ");
  scanf("%d", &choice);
   if (num > 0) {
    printf("%d is a positive number\n", num);
     if (num % 2 ==0)
       printf("%d is an even number\n", num);
     else
       printf("%d is an odd number\n", num);
     }
   else
     printf("%d is an odd number\n", num);
return(0)
}

This is a sample of an selection statement, other statements like switch have cases and depending on what case is presented, it will choose that case and go through the program.

Compiler

The compiler is a computer programs or a set of programs that transforms source code into object code. The reason for this is because when you write your source code (your syntax language code) it is not executable so in order to make it executable it needs to go through the compiler and make it object code.

Typedef

typedef assigns alternative names to existing types. They most often change the ones that are annoying, long or to make more sense with the implementation. Below is small example of how it could work

typedef int km_per_hour ;
typedef int points ;
 
km_per_hour current_speed ;
points high_score ;
...
 
void congratulate(points your_score) {
    if (your_score > high_score)
...

Enum

Enum is short for enumeration and what it does is instead of having int to represent a set of values, it uses a type of restricted set values instead. Without enum you would have to define each int type specifically with #define then whatever you assign it too. With enum you go like this:

 enum rainbowcolors {
 red,
 orange,
 yellow,
 green, 
 blue,
 indigo,
 violet) 
 }

Then the system will automatically assign a number to each one within the enum but you can set them to whatever you want. Its a easier way to set constants.

Union

A union declaration specifies a set of variable values and a tag naming the union. The variable values are called members of the union and can have different types.

union sign   /* A definition and a declaration */
{
    int svar;
    unsigned uvar;
} number;

This defines a union variable with sign type and declares a variable named number that has two members: svar, a signed integer, and uvar, an unsigned integer. This declaration allows the current value of number to be stored as either a signed or an unsigned value.

Structures

A structure is a collection of variables under a single name. These variables can be of different types, and each has a name which is used to select it from the structure. A structure is a convenient way of grouping several pieces of related information together.

 typedef struct {
          char name[64];
          char course[128];
          int age;
          int year;
  } student;
  
 student st_recc;

This is a structure of variables that is stored into student, which is renamed to st_recc.

Repetition/Iteration Structures

These are similar to the if and switch statements but they are loops. These consist of for, while, and do whiles. A for loop asks for a initialized variable, the parameters of the loop and an incrementation. So with these, the program will run until the parameters are met and it exits out. A while loop goes while a condition is true, and once that condition is untrue it exits out of the loop. A do while does what you want it to do, then checks to see if its true. If the condition is true, the program continues. Its similar to a while loop but with this it executes the program then checks the condition.

Preprocessor

It is a separate program called by the compiler as the first part of translation. The preprocessor handles instructions for the source file inclusion (#include), macro definitions (#define), and conditional inclusion (#if). The language of preprocessor instructions is agnostic to the grammar of C, so the C preprocessor can also be used independently to process other types of files.

unix Topics

$PATH

This is a variable that tells the shell what directory to search for executable files, in response to commands issued by the user. I took a script that was written that has the path “$password” and it uses similar actions as the $PATH variable.

  1 #!/bin/bash
  2 echo -n "Enter magic Password: "
  3 read Password
  4 if [ "$Password" = "`cat pss`" ];  then
  5     echo "Access Granted"
  6 else
  7     echo "access denied"
  8     exit 1
  9 fi
 10 exit 0
 11
lab46:~$ ./soaringeagle1.sh
Enter magic Password: candyland
Access Granted
lab46:~$

Wildcards

Wildcards are basically an indicator to the shell that some particular part of the filename is not known to you and the shell can insert a combination of characters in those places and then work on all the newly formed filenames. Some wildcards that are commonly used are: ? - match any single character * - match 0 or more of anything [] - any one of enclosed [^ ] - not anyone of enclosed

Tab Completion

This is a much faster way then typing out an entire line of commands and files on the command line. Instead of typing out the entire file you can hit “tab” and linux will do its best to finish it for you. So something that could take 5 seconds to type can take 1 second. If it matches 2 or more files you can do a double tab and it will cycle through them.

C

C is a programming language that is a fairly low level-language. Linux is written in this code and you can use linux to create, compile and execute these programs. Just open up a text editor and began typing away your program, assuming you know c language syntax. below is a example of a simple C code used in the VI text editor:

  1 #include <stdio.h>
  2 #include <math.h>
  3 int main()
  4 {
  5 unsigned short int bob=0;
  6 signed short int jim=0;
  7 printf("before , jim is %hd\n", jim);
  8 jim=pow(2, sizeof(jim)*8);
  9 printf("after, jim is %hd\n", jim);
 10 printf("jim is %d bytes\n", sizeof(jim));
 11 return(0);
 12 }
 13

Regular expressions

regular expressions are different ways to manipulate a text. Before we used and piped commands like grep and cut to manipulate our text and get exactly what we wanted. With regular expressions you can manipulate the text to something very precise in a more concise way. Some common regular expressions are:

^ - Match beginning of line
$ - match eof line
. - match any single character
* - match 0 or more of the previous
\< - match beginning of word
\> - match ending of word
[] - match any of what is enclosed
[^] - inverted brackets (do not match..)
() - grouping
| - or
\( \) - grouping for substitution

Killing a Process

When you have a process running in your terminal, whether in the background or foreground, you can easily kill it by using the command kill. There are many kill commands you can use to kill just about anything, as long as you have permission to do so. here is an example of killing another terminal you may have open:

lab46:~$ ps
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
dgirard3 14965  0.0  0.1  13632  2000 pts/40   SNs  00:11   0:00 -bash
dgirard3 25645  0.0  0.1  13624  1944 pts/41   SNs+ 01:00   0:00 -bash
dgirard3 25772  0.0  0.0   8584   972 pts/40   RN+  01:01   0:00 ps u
dgirard3 25993  0.0  0.0  13660     8 pts/33   SNs  Oct13   0:00 /bin/bash
dgirard3 26141  0.0  0.1  42464  1924 pts/33   SN+  Oct13   2:26 irssi
lab46:~$ kill -9 25645
lab46:~$

Now in the other terminal i used a tty command to figure out the PID (process Id) to figure out which process to kill, so when the kill -9 is executed the terminal bash process should quit and it will close out.

Backgrounding a process

When you want to run a command or a process but do not want to clog up the command line while doing so, run it in the background. In order to do this, write the command like you would normally do but this time put a ampersand at the end of it (&). This will put the running process into the background so you can do other things in the foreground. this example shows how the command would be executed by putting into the background, the number shows which process there is in the back so you can have more then one.

lab46:~$ cat hey&
[1] 27455
lab46:~$ #include <stdio.h>

int main()
{
        return(0);
}

Foregrounding a process

This is obviously the opposite to backgrounding but the foreground is where you begin once you bring up the terminal. Where you write and interact with the commands, thats the foreground. But when you background something and want to bring it back, all you have to do is use the command “fg % job number”. This should bring whatever job number you chose from the background to the foreground. If you want to resume it again in the background just use “fg %job number&”

Archiving/Unarchiving

Archiving is a useful tool to know in linux. It can take a collection of files and/or directories and put it all into one place, known as a archive. There are many archiving tools in the linux terminal and you choose one that fits your needs. I am going to show you an example of one archiver right now called Tar:

lab46:~$ ls
Desktop            archives           hi             public_html
Harchives.tar.bz2  bin                hi.c           regularexpressions
Maildir            botopen            hi.s           scriptrgex.sh
Puzzlewin          candy              in             soaringeagle.sh
Scanned1-1.png     closet             irc            soaringeagle1.sh
Scanned1.png       cmdcprog.c         killerwasp.sh  src
Scanned2-1.jpg     contact.info.save  lab1a.text     temp
Scanned2.jpg       courses            lyrics.mp3     temp.c
a.out              data               motd           the answer.txt
addscr.sh          destructo.sh       newdirectory   tmp
archive1.tar.gz    dl                 program        try3.png
archive2.zip       exper              program.c      wildcards
archivees          hey                pss
lab46:~$ tar cvzf Cexetension.tgz *.c
cmdcprog.c
hi.c
program.c
temp.c
lab46:~$ ls
Cexetension.tgz    archivees          hey            pss
Desktop            archives           hi             public_html
Harchives.tar.bz2  bin                hi.c           regularexpressions
Maildir            botopen            hi.s           scriptrgex.sh
Puzzlewin          candy              in             soaringeagle.sh
Scanned1-1.png     closet             irc            soaringeagle1.sh
Scanned1.png       cmdcprog.c         killerwasp.sh  src
Scanned2-1.jpg     contact.info.save  lab1a.text     temp
Scanned2.jpg       courses            lyrics.mp3     temp.c
a.out              data               motd           the answer.txt
addscr.sh          destructo.sh       newdirectory   tmp
archive1.tar.gz    dl                 program        try3.png
archive2.zip       exper              program.c      wildcards
lab46:~$

The archive should be highlighted red in your directory. What i did was archive any normal files with the c extension, hence why i called my archive “Cexetensions”. If you want to unarchive it, just find the extract commands you want in the man pages. I would use “tar xvzf Cexetensions.tgz” personally.

Compress/Decompress

If you want to have a smaller file because its too big to transfer or you just need more space, use the zip command. This command will compress files down and give it the file extension “.z”. When you compress you will not be able to read contents unless you decompress, and you would just use the decompress command.

lab46:~$ zip -r example3 closet
  adding: closet/ (stored 0%)
  adding: closet/skeleton (stored 0%)
  adding: closet/candy
zip warning: Permission denied
        zip warning: could not open for reading: closet/candy
  adding: closet/cake (deflated 2%)

zip warning: Not all files were readable
  files/entries read:  3 (42 bytes)  skipped:  1 (0 bytes)
lab46:~$ ls
Cexetension.tgz    archives           hi             regularexpressions
Desktop            bin                hi.c           scriptrgex.sh
Harchives.tar.bz2  botopen            hi.s           soaringeagle.sh
Maildir            candy              in             soaringeagle1.sh
Puzzlewin          closet             irc            src
Scanned1-1.png     cmdcprog.c         killerwasp.sh  temp
Scanned1.png       contact.info.save  lab1a.text     temp.c
Scanned2-1.jpg     courses            lyrics.mp3     the answer.txt
Scanned2.jpg       data               motd           tmp
a.out              destructo.sh       newdirectory   try3.png
addscr.sh          dl                 program        wildcards
archive1.tar.gz    example3.zip       program.c
archive2.zip       exper              pss
archivees          hey                public_html
lab46:~$

In there you should see a new zip file that i called example3. There are some errors saying permission denied, that is because i have some files with certain permissions on them so they can not be touched. But if you want to simply uncompress this file just use the command unzip and the contents should be extracted.

Shell Scripting

Shell scripting is a way to execute commands and processes by using one single executable file. You can write this in a text editor like vi, use very high level programming like pseudo coding and write it all out. then after that, save it and execute and it should run commands for you out on the commandline so you dont even have to type each command one by one. Here is an example:

 1 #!/bin/bash
  2 cd ~/tmp
  3 for file in `/bin/ls -1A `; do
  4     fname="`echo $file|cut -d'.' -f1`"
  5     mv -v $file $fname
  6 done
  7 exit 0

As you can see, it goes through the commands cd and mv, while doing some text manipulation.

Home Directory

The Home Directory is where you keep all of your files, your text files, audio files and any other directories you might have. All permissions are set for your use and yours only, unless you change it. the “~” represents that you are in your home directory and ls will list all your files in it. cd will also take you to your home directory no matter where you are.

lab46:~$ ls
Cexetension.tgz    archives           hi             regularexpressions
Desktop            bin                hi.c           scriptrgex.sh
Harchives.tar.bz2  botopen            hi.s           soaringeagle.sh
Maildir            candy              in             soaringeagle1.sh
Puzzlewin          closet             irc            src
Scanned1-1.png     cmdcprog.c         killerwasp.sh  temp
Scanned1.png       contact.info.save  lab1a.text     temp.c
Scanned2-1.jpg     courses            lyrics.mp3     the answer.txt
Scanned2.jpg       data               motd           tmp
a.out              destructo.sh       newdirectory   try3.png
addscr.sh          dl                 program        warning:.zip
archive1.tar.gz    example3.zip       program.c      wildcards
archive2.zip       exper              pss
archivees          hey                public_html
lab46:~$

cprog Objective

Objective

understand the difference between procedural and object-oriented languages

Method

To show the I know the difference, i will show 2 programs. One that is object oriented and one that is procedural.

Measurement

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

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

A list of instructions telling a computer, step-by-step, what to do, usually having a linear order of execution from the first statement to the second and so forth with occasional loops and branches. This is an procedural program. This is a very simple program but it can been seen it reads from top to bottom when it is executed.

   // program start.cpp
     #include  <iostream>
     using namespace std;
      
      struct   item     // a struct data type
        {
              int  keep_data;
         };
         
   void main()
    {
         item   John_cat, Joe_cat, Big_cat;
         int   garfield;   // a normal variable
        
         John_cat.keep_data = 10;      // assigning values
         Joe_cat.keep_data = 11;
         Big_cat.keep_data = 12;
         garfield = 13;
      
        // displaying data
        cout<<"Data value for John_cat is "<<John_cat.keep_data<<"\n";
        cout<<"Data value for Joe_cat is  "<<Joe_cat.keep_data <<"\n";
        cout<<"Data value for Big_cat is  "<<Big_cat.keep_data<<"\n";
        cout<<"Data value for garfield is "<<garfield<<"\n";
        cout<<"Press Enter key to quit\n";
        // system("pause");
    }

Object-oriented programming is a method of programming based on a hierarchy of classes, and well-defined and cooperating objects. This is a very simple example of object orientation, but if you can tell, it does not go step by step, it has structures with different values and they call each other. This is c++ language, c++ is OO most of the time, While c is very procedural.

Analysis

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

  • How did you do? I did pretty good
  • Room for improvement? yes there is
  • Could the measurement process be enhanced to be more effective? I could show more of the OOP and procedural programming
  • Do you think this enhancement would be efficient to employ? yes it would
  • Could the course objective be altered to be more applicable? How would you alter it? No i like it the way it is

unix Objective

Objective

Exposure to command-line tools and utilities. This is the ability to effectively use commands and utilities to navigate and use linux to its full potential.

Method

To prove i have reached this objective i will show various amounts of commands and tools that i can use in the terminal.

Measurement

lab46:~$ man
What manual page do you want?
lab46:~$ ls
Cexetension.tgz    archives           hi             regularexpressions
Desktop            bin                hi.c           scriptrgex.sh
Harchives.tar.bz2  botopen            hi.s           soaringeagle.sh
Maildir            candy              in             soaringeagle1.sh
Puzzlewin          closet             irc            src
Scanned1-1.png     cmdcprog.c         killerwasp.sh  temp
Scanned1.png       contact.info.save  lab1a.text     temp.c
Scanned2-1.jpg     courses            lyrics.mp3     the answer.txt
Scanned2.jpg       data               motd           tmp
a.out              destructo.sh       newdirectory   try3.png
addscr.sh          dl                 program        warning:.zip
archive1.tar.gz    example3.zip       program.c      wildcards
archive2.zip       exper              pss
archivees          hey                public_html
lab46:~$ cd archives
lab46:~/archives$ ls
abc.txt  filea  fileb  filec
lab46:~/archives$ cat filea
archives/abc.txt0000640001307400116100000000005207422045260013331 0ustar  dgirar                                                                                                 d3lab46This is an example file for use in CT173.
archives/fileb0000640001307400116100000000000007422045275013046 0ustar  dgirard3                                                                                                 lab46archives/filec0000640001307400116100000000000007422045275013047 0ustar  dgi                                                                                                 rard3lab46archivees/filea0000640001307400116100000000002407422045373013217 0usta                                                                                                 r  dgirard3lab46This contains text.
archivees/filez0000640001307400116100000000000007422045411013233 0ustar  dgirard                                                                                                 3lab46lab46:~/archives$ cd
lab46:~$ file closet
closet: directory
lab46:~$ ps | grep screen
dgirard3 15155  0.0  0.0  10084   852 pts/39   SN+  03:01   0:00 grep screen
lab46:~$ who
NAME       LINE         TIME             IDLE          PID COMMENT
synack   + pts/0        2011-10-18 13:38  old        14016 (184.72.226.125)
bblack1  + pts/1        2011-10-30 23:21 03:38       29290 (cpe-72-230-208-87.st                                                                                                 ny.res.rr.com)
jjohns43 + pts/2        2011-10-10 21:34 03:30        1072 (cpe-74-65-82-173:S.0                                                                                                 )
mgough   + pts/8        2011-10-11 19:15 03:48        4076 (rrcs-50-75-97-143:S.                                                                                                 0)
dgirard3 + pts/39       2011-10-31 02:57   .         14384 (cpe-67-241-224-129.s                                                                                                 tny.res.rr.com)
asowers  + pts/28       2011-10-30 11:57 15:03       30168 (cpe-67-241-233-254.s                                                                                                 tny.res.rr.com)
lab46:~$ ./hi
hello
lab46:~$ cd
lab46:~$ cd ..
lab46:/home$ ls
ab000126  aromero    bort      clawren2  ddragoo   dstorm3   gc007950    jbesecke  jjohns43  jsmit176  kcaton    llaughl3  mowens3    pdowd       rosenbll  squires   tl009536
abranne1  as012495   bowlett1  cmace1    dfoulk1   dtalvi    gcalkin3    jblaha    jjohnst8  jstrong4  kcook6    lleber    mp018526   plindsa1    rpage3    squirrel  tmizerak
abrunda1  ascolaro   brian     cmahler   dgirard3  dtaylo15  ggamarra    jblanch1  jkingsle  jsulli34  kcornel6  lmcconn4  mpaul6     pm004968    rpetzke1  srk3      tmong
acanfie1  asmedley   brobbin4  cmcavoy   dh002925  dtennent  gr015546    jbrant    jkremer1  jsulliv3  kdenson   lmerril3  mpresto4   pmcconn1    rraplee   srog      tp001498
acarpen5  asowers    bstoll    cmille37  dh018304  dtravis4  groush1     jbrizzee  jlantz4   jt011443  kgarrah1  mallis3   mshort3    qclark      rrichar8  ssmith85  triley2
acrocker  astrupp    btaber2   cmulkeri  dherman3  dwalrat1  gsnyder     jburlin1  jlazaar   jtongue2  kgaylord  mbeschle  mtaft4     radams4     rshaw8    sswimle1  ts004985
adexter   atoby      bwheat    cnicho13  dlalond1  dwells6   haas        jc006215  jluedema  jtreacy   kinney    mbonacke  mwagner3   rberry3     rthatch2  strego    vcordes1
adilaur1  atownsle   bwilso23  comeaubk  dm005264  dwrigh18  hansolo     jcardina  jm010967  jtripp    kkrauss1  mbrigham  mwarne11   rbuchan7    ryoung12  svrabel   wag2
aettenb3  atreat2    bwilson3  cpainter  dmagee3   eberdani  hclark9     jcosgro4  jmanley3  jv001406  klynch3   mbw6      mwitter3   rcaccia1    sblake3   swarren4  wedge
afassett  awalke18   cas21     critten1  dmay5     efarley   hepingerjj  jdavis34  jmille59  jvanott1  kpryslop  mclark35  nandre     redsting3d  sc000826  sweller5  wezlbot
agardin4  bblack1    caustin8  csleve    dmurph14  egarner   hhabelt     jdawson2  jmitch22  jwalrat2  kreed11   mcooper6  nbaird     reedkl      sclayton  swilli31  wfischba
ajernig2  bbrown17   ccaccia   cspenc12  dpadget8  egleason  hps1        jdrew     jmunson   jwhitak3  kscorza   mdecker3  nblancha   rfinney2    sedward9  syang     wknowle1
ajoensen  bdevaul    ccarpe10  csteve16  dparson3  emorris4  hramsey     jeisele   jmyers7   jwilli30  ksisti2   mdittler  ngraham2   rglover     sjankows  synack    wroos
alius     bewanyk    cchandan  cwagner1  dpotter8  en007636  hshaikh     jellis15  jo009612  jwilso39  kwalker2  mearley1  nrounds    rhender3    sjelliso  tcolli12  ystebbin
amorich1  bfarr2     ccranda2  cwilder1  dprutsm2  erava     hwarren1    jfrail    jphill17  jwood36   lburzyns  mfailing  nsano      rj005436    smacombe  tdoud     zlittle
anarde    bh011695   cderick   cwoolhis  drobie2   erebus    ian         jfurter2  jr018429  jzimmer5  lcrowley  mgough    nsr1       rjohns41    smatusic  tfitch1   zward
anorthr3  bherrin2   cdewert   darduini  ds000461  estead    imaye       jh001093  jrampul1  kamakazi  ld010818  mguthri2  nvergaso   rkapela     smclaug3  tgalpin2
anowaczy  bhuffner   cforman   dates     ds003420  eveilleu  jandrew9    jhall40   jsabin1   kbell1    leckley   mhenry9   nwebb      rlott       smd15     thatcher
ap016986  bkenne11   cgoodwin  db010905  dschoeff  ewester1  javery9     jhammo13  jschira1  kboe      lgottsha  mkellogg  oppenheim  rm002127    smilfor3  tjohns22
appelthp  bnichol7   ckelce    dchilso3  dshadeck  ezajicek  jbaez       jj001572  jshare1   kc017344  lh000592  mkelsey1  pclose     rmoses      spetka    tkane1
aradka    bobpauljr  ckuehner  dcicora1  dshreve   fclark1   jbarne13    jjansen4  jshort6   kcard2    lhubbar3  mmatt     pcremidi   rnewman     spline    tkiser
lab46:/home$ cd ..
lab46:/$ ls
bin  boot  dev  etc  home  initrd.img  lib  lib32  lib64  lost+found  media  mnt  opt  proc  root  sbin  selinux  srv  sys  tmp  usr  var  vmlinuz
lab46:/$ cd
lab46:~$ who
NAME       LINE         TIME             IDLE          PID COMMENT
synack   + pts/0        2011-10-18 13:38  old        14016 (184.72.226.125)
bblack1  + pts/1        2011-10-30 23:21 03:40       29290 (cpe-72-230-208-87.stny.res.rr.com)
jjohns43 + pts/2        2011-10-10 21:34 03:32        1072 (cpe-74-65-82-173:S.0)
mgough   + pts/8        2011-10-11 19:15 03:50        4076 (rrcs-50-75-97-143:S.0)
dgirard3 + pts/39       2011-10-31 02:57   .         14384 (cpe-67-241-224-129.stny.res.rr.com)
asowers  + pts/28       2011-10-30 11:57 15:05       30168 (cpe-67-241-233-254.stny.res.rr.com)
lab46:~$

next i will open up the vi editor.

lab46:~$ vi forobjective
lab46:~$

 1  this is for the objective to prove i can use and open up vi. I cant show any of the shorcuts i have used on here however i can at least show my ability to be on here

there are other text editors like nano. If i wanted i could easily read this file in the command line with a cat command. VI can also be used to shell script which i have many scripts wrriten (files with sh extension) i also have c programs used in the vi editor (.c extensions) I also have a file that edits vi once it opens, i will show you.

 1 syn on
  2 set tabstop=4
  3 set shiftwidth=4
  4 set nu
~
~

These are in the vi text editor and this will change my vi settings everytime i go to use it.

Analysis

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

  • How did you do? Not too bad
  • Room for improvement? Yes there is
  • Could the measurement process be enhanced to be more effective? Yes, i could show more use of commands or show how effective i can use them. I showed i could navigate and execute commands and tools but i feel it could be further shown, i just dont know how.
  • Do you think this enhancement would be efficient to employ? Yes it definitely would
  • Could the course objective be altered to be more applicable? How would you alter it? No i like it where it stands

Experiments

Experiment 1

Question

Can there be a space in a file/directory name?

Resources

Any information will be knowledge from class.

Hypothesis

I believe you can because its not that hard to put it into quotes of some sort to show that its all one thing, and not separated.

Experiment

I will show you a file with a space in it or create one of my own to prove its possible.

Data


lab46:~$ ls
Cexetension.tgz    archives           hey            public_html
Desktop            bin                hi             regularexpressions
Harchives.tar.bz2  botopen            hi.c           scriptrgex.sh
Maildir            candy              hi.s           soaringeagle.sh
Puzzlewin          closet             in             soaringeagle1.sh
Scanned1-1.png     cmdcprog.c         irc            src
Scanned1.png       contact.info.save  killerwasp.sh  temp
Scanned2-1.jpg     courses            lab1a.text     temp.c
Scanned2.jpg       data               lyrics.mp3     the answer.txt
a.out              destructo.sh       motd           tmp
addscr.sh          dl                 newdirectory   try3.png
archive1.tar.gz    example3.zip       program        wildcards
archive2.zip       exper              program.c
archivees          forobjective       pss
lab46:~$

before this experiment i forgot i found a file that was named “the answer.txt” for project i did and so it is possible to create and read one but i am going to attempt to make my own to see if i can do it.

lab46:~$ mkdir "for experiment"
lab46:~$ ls
Cexetension.tgz    archives           forobjective   pss
Desktop            bin                hey            public_html
Harchives.tar.bz2  botopen            hi             regularexpressions
Maildir            candy              hi.c           scriptrgex.sh
Puzzlewin          closet             hi.s           soaringeagle.sh
Scanned1-1.png     cmdcprog.c         in             soaringeagle1.sh
Scanned1.png       contact.info.save  irc            src
Scanned2-1.jpg     courses            killerwasp.sh  temp
Scanned2.jpg       data               lab1a.text     temp.c
a.out              destructo.sh       lyrics.mp3     the answer.txt
addscr.sh          dl                 motd           tmp
archive1.tar.gz    example3.zip       newdirectory   try3.png
archive2.zip       exper              program        wildcards
archivees          for experiment     program.c
lab46:~$

ok its possible :)

Analysis

Based on the data collected:

  • was your hypothesis correct? yes it was
  • was your hypothesis not applicable? It was
  • is there more going on than you originally thought? (shortcomings in hypothesis) Nope, i knew what was going to happen, just wasnt sure
  • what shortcomings might there be in your experiment? Maybe i could do it another way
  • what shortcomings might there be in your data? there are none

Conclusions

I am certain that your files and directories are not limited to a single word line, it can have spaces you just have to know how to manipulate your command line the right way to work for you.

Experiment 2

Question

Can you compile assembly code the same way you compile c code?

Resources

Just going to take what i know from class and implement it here

Hypothesis

I think you can compile it the same way, essentially its the same code just with different syntax. I am just not sure if it requires anything special to be done because its such a low level, so maybe it will act differently.

Experiment

I will show you within the lab46 terminal by running commands and executing a program.

Data

lab46:~$ ls
Cexetension.tgz    archives           forobjective   pss
Desktop            bin                hey            public_html
Harchives.tar.bz2  botopen            hi             regularexpressions
Maildir            candy              hi.c           scriptrgex.sh
Puzzlewin          closet             hi.s           soaringeagle.sh
Scanned1-1.png     cmdcprog.c         in             soaringeagle1.sh
Scanned1.png       contact.info.save  irc            src
Scanned2-1.jpg     courses            killerwasp.sh  temp
Scanned2.jpg       data               lab1a.text     temp.c
a.out              destructo.sh       lyrics.mp3     the answer.txt
addscr.sh          dl                 motd           tmp
archive1.tar.gz    example3.zip       newdirectory   try3.png
archive2.zip       exper              program        wildcards
archivees          for experiment     program.c
lab46:~$ gcc -o experiment hi.s
lab46:~$ ls
Cexetension.tgz    archives           for experiment  program.c
Desktop            bin                forobjective    pss
Harchives.tar.bz2  botopen            hey             public_html
Maildir            candy              hi              regularexpressions
Puzzlewin          closet             hi.c            scriptrgex.sh
Scanned1-1.png     cmdcprog.c         hi.s            soaringeagle.sh
Scanned1.png       contact.info.save  in              soaringeagle1.sh
Scanned2-1.jpg     courses            irc             src
Scanned2.jpg       data               killerwasp.sh   temp
a.out              destructo.sh       lab1a.text      temp.c
addscr.sh          dl                 lyrics.mp3      the answer.txt
archive1.tar.gz    example3.zip       motd            tmp
archive2.zip       exper              newdirectory    try3.png
archivees          experiment         program         wildcards
lab46:~$ ./experiment
hello
lab46:~$

I took the “hi.s” which is machine language and ran the compile command to compile it into “experiment” and it still executes just fine

Analysis

Based on the data collected:

  • was your hypothesis correct? Yes it was
  • was your hypothesis not applicable? It can be
  • is there more going on than you originally thought? (shortcomings in hypothesis) I thought something weird would happen honestly
  • what shortcomings might there be in your experiment? No there is not
  • what shortcomings might there be in your data? There are none

Conclusions

As long as you have the right syntax of whatever code you are using, you can compile it withn the lab46 terminal using gcc -o. It will compile and execute normally

Experiment 3

Question

What happens when you mix up the .c file and the filename when compiling in linux?

Resources

My information comes from class :) so Matt Haas

Hypothesis

I believe it will not do anything to it, it shouldnt matter, right? as long as it has both files it should just know which is which.

Experiment

i will write a sample program and compile it the wrong way

Data

  1 #include <stdio.h>
  2 int main()
  3 {
  4     printf("hello\n");
  5     return(10);
  6 
  7 }

this is an easy simple code that i wrote, just for the use of this experiment. Now we will try to compile it the wrong way:

lab46:~/unixprog$ gcc -o hi.c ghjk
gcc: ghjk: No such file or directory
gcc: no input files
lab46:~/unixprog$ gcc -o poop hi.c
lab46:~/unixprog$ 

It yells at me when i do it the wrong way.

Analysis

No my hypothesis was wrong. I feel it was applicable just it was incorrect. There was nothing that i knew that wasnt going on and i knew what to expect if something happened. There were no shortcomings in either data or experiment.

Conclusions

This was an easy project and i just needed to know what would happened if i did this, and no i know.

Part 3

Entries

November 3, 2011

This week for class we did a mix bewteen working on stuff and learning stuff. Tuesday we just worked on projects and opus, and we got to mess with the video wall. We learned to display images on others computers user their server region (where they happen to be sitting) and we were able to display logos, eyes and anything else we could find. WE played with that and also worked on things. I worked on my optical archiving, its done it just needs to be documented and once that is complete, the project is complete. Thursday we took a spring 2012 catalog course list and cut it down with regular expressions and grep and sed and other commands. We took an almost un readable html code and made it so anyone can read it easily. For C i have read some of the book and started 2 projects, multiplication table and fun with colors. I also finished the datatypes and soon these programs will be finished and executed well.

November 10, 2011

This week we worked with regular expressions and taking apart an html text. We took apart a course catalog from an unreadable version to a version that any person can read. It took a long expression because of how much was needed to be removed but in the end it was not that hard. We used sed and cut and the list of regular expressions you have learned. And on the side of this, we have taken some time to just work on projects and and opus. I have been working on the encoding and its so close to being finished, its just has some minor malfunctions that needs to be fixed. And in C, i have been working on roshambo and multiplication table. I got the table finished and documented and just starting on roshambo. Its not going to be too hard, its the logic that might be a little confusing. But other than that, that is what i have worked on this week and what has been learned.

November 17, 2011

This week we did the same thing just took the text apart a little bit differently. We used sed and regular expressions as usual but this time we used a new command called tr. tr translates or deletes characters, so you are basically you are just replacing characters with another character so like you want the letter “a” to be deleted. replace it with “\n” and it will cut out that word and just have an endline in the place. Regardless of that, all we did was play time and i worked on my optar project and i got it finished and i have made my own optar project for everyone to use. In c i have been just working on projects and trying to get as many as i can done. I have finished one project and one is close to done, just need to add a few loops and variables and everything should fall into place.

November 24, 2011

This week was break week so not much was done, I still had class on tuesday and we took that day as a play day and just worked on whatever was needed to be done, I worked a little bit on some projects but not all of them. I have 7 projects but 2 have yet to be finished and i probably will have to create a few more to reach all my attributes. Until then i only have a few projects to go in this class and the EOC experience. In C i have been doing the same thing and just doing projects. I am in a rut on my roshambo so i have moved on and will come back to it whenever i finish a few other projects. I also have a EOC experience for this class as well so i need to do around 4 projects in this class plus that. So all tpgether i have 2 EOCE and 6+ projects to complete.

cprog Topics

Recursion

Recursion is technically another way of looping but its not looping. Its where a function will call itself and essentially loops itself.

This is a simple example of recursion

void recurse()
{
  recurse(); //Function calls itself
}

int main()
{
  recurse(); //Sets off the recursion
}

this is more of a detailed sample of recursion.

#include <iostream>

using namespace std;

void recurse ( int count ) // Each call gets its own count
{
  cout<< count <<"\n";
  // It is not necessary to increment count since each function's
  //  variables are separate (so each count will be initialized one greater)
  recurse ( count + 1 );
}

int main()
{
  recurse ( 1 ); //First function call, so it starts at one        
}

Command-line arguments

It is possible to use commands from the command line in linux to your program in c/c++. The main can actually accept two arguments: one argument is number of command line arguments, and the other argument is a full list of all of the command line arguments. an example of this is in the code block below.

#include <stdio.h>

int main ( int argc, char *argv[] )
{
    if ( argc != 2 ) 
    {
        
        printf( "usage: %s filename", argv[0] );
    }
    else 
    {
        
        FILE *file = fopen( argv[1], "r" );

        
        if ( file == 0 )
        {
            printf( "Could not open file\n" );
        }
        else 
        {
            int x;
            
            while  ( ( x = fgetc( file ) ) != EOF )
            {
                printf( "%c", x );
            }
            fclose( file );
        }
    }
}

Code stages (Source, Object, Binary)

When you write programs, that code you have written goes through a few stages. It turns into a different format of code, but it is still the same. Source code is what you type out on your text editor or wherever you type it. Then when you go to compile, your code becomes object code after the steps where its does a syntax check and token check, it goes into a the assembler and it turns into object code. Then after it checks the libraries and code, it becomes executable which is binary.

C Library, Libraries, and Makefiles

The C library is essentially your main library for programming. It contains your main ISO functions that you need such as printf and scanf. You use these on a daily basis so you can just put these libraries up and full access to these function. There are of course other libraries such as math.h, for your mathematical uses and such. Libraries allow you to pull out functions that are very common, so you dont have to write code for it every time. Then you have makefiles, this is where you can take a huge program, take the different parts inside it (such as main, functions and headers) and you can compile them separately. But after its compiled it goes into one file for execution. This is the better way to go because if there is an error, it is very easy to spot and fix instead of going through a huge code.

Multi-file programs (how to structure, how to compile)

A multi-file program works similar to makefiles. If you have a big file, with a big main function and a big side function, you dont want to compile it, find something wrong and search through all that code. So with a multi-file, it will take each part of the program (the main function, other functions, and even header files) and it will put them in their own separate files, compile them and put it all into one working file for you to use.

Version Control (checkout, commit, update, add, log)

Version control is the same as revision control, this is the ability to track and control the changes in projects, programs or file changes. When you change a project in some way, it saves the older version. So you are able, if a mistake is made, you can go back a bring back an older copy and start from where you were before. When you checkout you are going back into the repository for a working copy, so go back a grab a copy. When you commit, yoou make a change on the project or store a change in the version control database. Updating is where you make sure that commits are on your copy or that your copy is “up to date” with everyone elses. Adding is where you can add changes into a copy, as long as that they do not overlap each other, if it does, that is an issue with the head person of the project. log is where you leave a message with your commit to let a person know what has been done and why.

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

I/O streams are there for you to streams classes that can read from a file, write to a file or do both from/to a file. cin is for writing to a file, it accepts user input and goes to a file for use later on. cout reads from a file and prints out the data from a place you pull from. cerr is there incase you run into an error and this will check for those and let you know. These are many stream opators that you will use in c++ you could have int, char and float from the ostream. You can pull out a lot of operators for you to use in your program.

Exception Handling (throw, try, catch) [C++]

Exceptions handling is a way to help us react to common circumstances like a run time error, and we do this by using special functions called handlers. So you will make a separate function with a try block. This try block will execute the throw and catch. The throw excepts one parameter and acts as an argument. The type of parameter here is important because whatever it is here has to be the same for the catch argument, so it can be “caught”. catch is also has a single parameter and acts as an argument as well. However you dont have to have a specific data type so you can chain catch expressions. The thing that would happen is if it does not have a corresponding datatype with a throw, it just wont execute.

// exceptions
#include <iostream>
using namespace std;

int main () {
  try
  {
    throw 20;
  }
  catch (int e)
  {
    cout << "An exception occurred. Exception Nr. " << e << endl;
  }
  return 0;
}

Namespaces [C++]

Namespaces allows a person to take entities like classes, objects and functions, and put it under a name. This is so instead of have multiple entities in one big global scope, you can smaller sub-scopes with their own name. You also have a tool called using, which allows you to make a directive of which names you want to use.

// using
#include <iostream>
using namespace std;

namespace first
{
  int x = 5;
  int y = 10;
}

namespace second
{
  double x = 3.1416;
  double y = 2.7183;
}

int main () {
  using first::x;
  using second::y;
  cout << x << endl;
  cout << y << endl;
  cout << first::y << endl;
  cout << second::x << endl;
  return 0;
}

Polymorphism/Virtual Functions [C++]

Polymorphism is where you can implement ways of a function to work different ways. So say you wrote a program for a bird flying, it could flap its wings like crazy or it could glide amazingly. The function does not care how it flies, just that it does fly. So you could create a function that could work for any function from any class you make.

class bird
{
public:
  virtual void fly() = 0;
}

Migrate function that can accept any bird.

void migrate(bird* tweetiepie)
{
  // ...
  tweetiepie->fly();
  // ...
}

Main program

class swallow : public bird
{
public:
  virtual void fly()
  {
    flap_wings_like_crazy();
  }
};

class albatross : public bird
{
public:
  virtual void fly()
  {
    glide_majestically_over_the_waves();
  }
};

then with this you could choose any bird and throw it into the migrate function

swallow s;
albatross a;

migrate(&s);
migrate(&a);

Function Overloading [C++]

This is where you declare more than one function in the same scope. So say you have a print function that displays an int. Well in the same scope, you also have print functions that displays a double and a char. When you overload a function you must have different datatype or different arguments in order for it to be properly overloaded. In easier terms, you can kind of mix functions together to all run in one big function, this is a similar form of polymorphism.

#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");
}

Abstract Base class[C++]

An ABC is classes that deal with a abstract concept. Like the concept of vehicles, when you say vehicles one thinks of a car. Well in reality a car is not the only vehicle, which makes it abstract. In vehicle you have space shuttle, ocean liner, bicycle, car, van and etc. So in an implementation view say you have a class of vehicle (class vehicle) and you have derived classes of cars. bicycles and etc. An ABC is a class that has one or more pure virtual member functions. You cannot make an object (instance) of an ABC

unix Topics

X Window System

This is a computer software system and network protocol that provides a basis for graphical user interfaces (GUIs) and rich input device capability for networked computers. It creates a hardware abstraction layer where software is written to use a generalized set of commands, allowing for device independence and reuse of programs on any computer that implements X. One implementation with this is a simple and fun one called xeyes, it brings up a pair of eyes that will follow your mouse. This can only be done on computers with x system hardware remember. But that is something basic, it brings up fun graphical objects you can use.

High-Performance computing

HPC develops supercomputers and software to run on supercomputers. A main area of this discipline is developing parallel processing algorithms and software: programs that can be divided into little pieces so that each piece can be executed simultaneously by separate processors. In easier terms, you can run one screen across 12 computers or more. So it can be a wall of 12 computer screens and combined into one big one.

The VI text editor

The VI text editor is a very powerful text editor on the linux system. It is not like any other ordinary editor, most have commands and line editing in one, this one has separate modes. You have a command mode and a insert mode. Command mode lets you do commands like save, delete, cut, copy and many more you could normally do on other text editors. In insert mode is where you will be doing most work. You type whatever you want here and such. Generally you switch between the 2 modes with esc or I, but there are other advanced ways, like A will take you into insert mode at the place after your cursor, to be much more precise and faster when editing your text. Also a separate file called vimrc.info allows you to customize it to the way you want.

  1 This is an example of vi. You can type files that are text or make executabl
    e. The number you see to the left are preset and when programming, i have
    them preset to highlight. This is a very good editor and can be amazing once 
    you get the hang of it.
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
-- INSERT --                                                  1,178         All

Enviroment Variable

Within the shell, a variable that is stored in the environment. The environment is inherited by all the child processes,so the environment variables can be thought as global variables. They are not strictly global however because changes by the child are not propagated by the parent. So some things like $PATH, that is a environment variable. This searches through a list of files and directories for the command you may have typed in. You can add your own paths in if you want to run any commands of your own from your home directory or where ever.

lab46:~$ echo $PATH
/home/dgirard3/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games
lab46:~$

This is where i can run commands and programs from.

Text Processing

This is where you manipulate text in anyway that you want. You can make it to be in any format or you can replace things with other things! or just make it so its easier to read. text manipulation uses regular expressions and commands like cut, grep and sed.

lab46:~$ cat Schedulecut
cat spring2012-20111103.html | grep 'ddtitle' | sed 's/^<TH CLASS="ddtitle".*crn_in=.....">//g' | sed 's/<\/A.*$//g' | sed 's/^\(.*\) - \([0-9][0-9][0-9][0-9][0-9]\) - \(.*\) - \([0-9][0-9][0-9]\)$/\2:\3-\4:\1/g' | sort | less
lab46:~$

this example above was to cut down a html formatted course list into a easily readable format that anyone could read. If you are able to master this, you will be greatly respected.

Copying

Copying in linux is very simple. If you want to copy a directory or a file just use the cp command along with the file you want to copy and the name of the file you want the copy to be called.

lab46:~$ vi copyme
lab46:~$ ls
Cexetension.tgz   a.out              irc           puzzlepaper
Desktop           badname            lab1a.text    regularexpressions
Documents         badname.tgz        motd          scripts
Downloads         bin                networkcmds   spring2012-20111103.html
FilelistforOPTAR  candy              newdirectory  src
Maildir           classlog12         out           test
Music             contact.info.save  outfile       test2
Nyan Cat.wav      copyme             output        tmp
Public            courses            pgm2ps        unixprog
Schedulecut       data               pss           wildcards
Templates         dl                 public_html
Videos            in                 puzzlebox
lab46:~$ cp copyme hiopus
lab46:~$ ls
Cexetension.tgz   a.out              in            puzzlebox
Desktop           badname            irc           puzzlepaper
Documents         badname.tgz        lab1a.text    regularexpressions
Downloads         bin                motd          scripts
FilelistforOPTAR  candy              networkcmds   spring2012-20111103.html
Maildir           classlog12         newdirectory  src
Music             contact.info.save  out           test
Nyan Cat.wav      copyme             outfile       test2
Public            courses            output        tmp
Schedulecut       data               pgm2ps        unixprog
Templates         dl                 pss           wildcards
Videos            hiopus             public_html
lab46:~$

Moving/Renaming

Another simple process in linux. This is where you can move a file into a new directory or move a directory into a directory. All you need is the command mv, the file/directory you want to move and where you want to move it.

lab46:~$ vi moveme
lab46:~$ mkdir gohere
lab46:~$ mv moveme gohere
lab46:~$ ls
Cexetension.tgz   Maildir       Templates    bin                courses  in           newdirectory  pss                 scripts                   tmp
Desktop           Music         Videos       candy              data     irc          out           public_html         spring2012-20111103.html  unixprog
Documents         Nyan Cat.wav  a.out        classlog12         dl       lab1a.text   outfile       puzzlebox           src                       wildcards
Downloads         Public        badname      contact.info.save  gohere   motd         output        puzzlepaper         test
FilelistforOPTAR  Schedulecut   badname.tgz  copyme             hiopus   networkcmds  pgm2ps        regularexpressions  test2
lab46:~$ cd gohere
lab46:~/gohere$ ls
moveme
lab46:~/gohere$

Removing

Removing files and directories is easy as well. Choose whatever file or directory you want and use the rm command to remove it.

lab46:~/gohere$ cd
lab46:~$ rmdir gohere
rmdir: failed to remove `gohere': Directory not empty
lab46:~$ cd gohere
lab46:~/gohere$ rm moveme
rm: remove regular file `moveme'? y
lab46:~/gohere$ cd
lab46:~$ rmdir gohere
lab46:~$

As you see here, in order to remove a directory it must be empty and you have to add a “dir” to the rm command to specify its a directory and not just a file.

Creating

This is also very simple. To create a file without any data in it, just use “the touch of god” or the touch command. It should create a file with 0 bytes, completely empty. But if you want a file with data in it all you need to do is type out what you want to put in the file and use the “>” to direct it to a existing file or one you create right on the spot. And in order to make a directory all you need is to use mkdir. It should give you a empty directory to store your files.

lab46:~$ touch touchme
lab46:~$ echo touchme
touchme
lab46:~$ file touchme
touchme: empty
lab46:~$ echo "yep... DIARRHEA" > invaderzim
lab46:~$ file invaderzim
invaderzim: ASCII text
lab46:~$ cat invaderzim
yep... DIARRHEA
lab46:~$ mkdir directoryofdoom
lab46:~$ ls
Cexetension.tgz   Maildir       Templates    bin                courses          in          networkcmds   pgm2ps       regularexpressions        test2
Desktop           Music         Videos       candy              data             invaderzim  newdirectory  pss          scripts                   tmp
Documents         Nyan Cat.wav  a.out        classlog12         directoryofdoom  irc         out           public_html  spring2012-20111103.html  touchme
Downloads         Public        badname      contact.info.save  dl               lab1a.text  outfile       puzzlebox    src                       unixprog
FilelistforOPTAR  Schedulecut   badname.tgz  copyme             hiopus           motd        output        puzzlepaper  test                      wildcards
lab46:~$

Current working directory

Your current working directory is where you are at that moment. It is where you run your processes and execute commands. You can figure out where exactly you are with the command pwd.

lab46:~$ pwd
/home/dgirard3
lab46:~$

Types of Files

There are many types of files in the linux system, actually everything is a file on this. There a few different types of files however. You have directories which hold these files. You have regular files such as text files, you have special files which holds programs and special data, you have executable which can execute programs and then you have data files which holds some sort of data link.

Files

Everything is a file in linux. Everything that you do has some sort of file to hold that data. Files are, in way, similar to text documents that you would keep and store away. And when you wanted that information, you go to where you put the paper and read the information. Thta is what a file is, just in the computer world its a resource for storing information. So say you use a command on the command line, it is actually using a path to go read directories and finding the file program that can enable you to use that command. Everything has a place in a file somewhere.

cprog Objective

Objective

know how to use arrays and pointers. This objective is basically saying if you understand the concept of arrays and pointers and an example will be shown here.

Method

I will explain how an array and a pointer will work through explanation and small examples.

Measurement

Arrays are essentially groups of data stored sequentially. Arrays can be a hard concept to understand but it is actually very simple. For a basic array all you really need is how to create and address them and how to manipulate the array. Well creating an array is simple this is all you need to do:

int array[20]; //This is an array that will hold int values
char array2[20] //This array will hold char values;

The Arrays above are similar in nature, they just hold different data types. The name of the array comes before the brackets so the top one is called array and the bottom one is array2. Then what is inside the brackets is the size of that array, how many variables are going into it. So this is a size of 20, going from 0-19. You can easily print out you elements you have inside your arrays as well.

int myArray [5] = {1,2,3,4,5};
/* To print all the elements of the array
for (int i=0;i<5;i++){
   printf("%d", myArray[i]);
}

Here is an easy way to print out the elements you have stored into your array. Now you can also perform operations inside an array, here is a sample program that shows how it all works.

#include <stdio.h>
void oneWay(void);
void anotherWay(void);
int main(void) {
   printf("\noneWay:\n");
   oneWay();
   printf("\nantherWay:\n");
   anotherWay();
}

/*Array initialized with aggregate */
void oneWay(void) {
   int vect[10] = {1,2,3,4,5,6,7,8,9,0};
   int i;
   for (i=0; i<10; i++){
       printf("i = %2d vect[i] = %2d\n", i, vect[i]);
   }
}

/*Array initialized with loop */
void anotherWay(void) {
   int vect[10];
   int i;
   for (i=0; i<10; i++)
        vect[i] = i+1;
   for (i=0; i<10; i++)
        printf("i = %2d vect[i] = %2d\n", i, vect[i]);
}

/* The output of this program is
   oneWay:
   i = 0 vect[i] = 1
   i = 1 vect[i] = 2
   i = 2 vect[i] = 3
   i = 3 vect[i] = 4
   i = 4 vect[i] = 5
   i = 5 vect[i] = 6
   i = 6 vect[i] = 7
   i = 7 vect[i] = 8
   i = 8 vect[i] = 9
   i = 9 vect[i] = 0

   antherWay:
   i = 0 vect[i] = 1
   i = 1 vect[i] = 2
   i = 2 vect[i] = 3
   i = 3 vect[i] = 4
   i = 4 vect[i] = 5
   i = 5 vect[i] = 6
   i = 6 vect[i] = 7
   i = 7 vect[i] = 8
   i = 8 vect[i] = 9
   i = 9 vect[i] = 10
   */

This is the operations with an array. Your array can also be multi dimensional, like an array inside an array. When you have an array you have rows and columns, The first [] will hold your number of rows and your second [] will hold your columns. Now to initialize this is a little bit different. It works like this:

int values [3] [4] = {
	{
		1, 2, 3, 4
	}
	{
		5, 6, 7, 8
	}
	{
		9, 10, 11, 12
	}
};

here is an example of a multi dimensional array storing and printing its values:

main ( )
{
	int stud [4] [2];
	int i, j;
	for (i =0; i < =3; i ++)
	{
		printf ("\n Enter roll no. and marks");
		scanf ("%d%d", &stud [i] [0], &stud [i] [1] );
	}
	for (i = 0; i < = 3; i ++)
	printf ("\n %d %d", stud [i] [0], stud [i] [1]);
}

Now with arrays comes the magical use of pointers. A pointer, in general, is a number representing a memory address. We call it a pointer because it is pointing to a place in memory we want to work with. You can establish what kind of pointer you want to work with like an int or char or even void. In order to point to something you use the asterisk (*) in front of the variable name. So here is a small of example of it. Now in the for loop, both lines will do the same thing, just in a different way:

#include <stdio.h>

int my_array[] = {1,23,17,4,-5,100};
int *ptr;

int main(void)
{
    int i;
    ptr = &my_array[0];     /* point our pointer to the first
                                      element of the array */
    printf("\n\n");
    for (i = 0; i < 6; i++)
    {
      printf("my_array[%d] = %d   ",i,my_array[i]);   /*<-- A */
      printf("ptr + %d = %d\n",i, *(ptr + i));        /*<-- B */
    }
    return 0;
}

Line A Just accesses the array like it normally would but line B points to the spot where you would like to begin and move on. This is a very simple concept of using a pointer but it gets the point across. You just pick a spot in memory and “point” to it, its that easy :D. Now it does get more complicated when you start pointing to strings or functions even.

Analysis

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

  • How did you do? I think i did pretty good
  • Room for improvement? Yes, there is so much more i can learn
  • Could the measurement process be enhanced to be more effective? Yes, possibly more information on certain parts
  • 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 i like how it is now

unix Objective

Objective

experience the connection between UNIX and C

Method

I will show how linux comes with a compiler built in “gcc”.

Measurement

Linux has its own compiler for The C source code. Its called gcc, and you use it to compile c programs written in vi text editor or nano. here is an example program that was written using C in VI:

  1 /*--- range.c begin ---
  2  * Compile with: gcc -o range range.c -lm
  3  * Execute with: ./range
  4  */
  5 #include <stdio.h>
  6 #include <math.h>
  7 
  8 int main()
  9 {
 10     // Variables
 11     unsigned long long int quantity = 0;
 12     unsigned long long int uc = 0;
 13     signed long long int sc = 0;
 14 
 15 // Display information for unsigned long int data type
 16     printf("An unsigned long int is %d bytes\n", sizeof(uc));
 17     printf("The range of an unsigned long int is %llu to %llu\n", uc, (uc-1));
 18     quantity = (unsigned long long int)(uc-1);    // What does this line do?
 19     printf("An unsigned long int can store %llu unique values\n\n", quantity);
 20 
 21 // Display information for signed long int data type
 22     printf("A signed long int is %d bytes\n", sizeof(sc));
 23     quantity = (unsigned long long int)pow(2, (sizeof(sc)*8)); // What is happening?
 24     printf("The range of a signed long int is %lld to %lld\n", (sc-(quantity/2)), (sc+(quantity/2)-1));
 25     printf("A signed long int can store %llu unique values\n\n", quantity);
 26 
 27     return(0);
 28 }
 29 //--- range.c end ---
 

Here is how you compile this program into an executable file:

gcc -o example datatypes.c

Linux works really well with the C language and i would so since it is written in C. Everything that this system does is run by a C program or a shell script. C is found everywhere on the linux system and these are like a perfect match for each other.

Analysis

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

  • How did you do? Not so good, i could do better but this part would delete on me every time i typed it
  • Room for improvement? Oh definitely
  • Could the measurement process be enhanced to be more effective? yes, there could be more
  • Do you think this enhancement would be efficient to employ? Yes, it gets the point across
  • Could the course objective be altered to be more applicable? How would you alter it? No it is fine, just technical error was making this difficult.

Experiments

Experiment 1

Question

Can i sudo onto linux?

Resources

My information comes from class :) so Matt Haas

Hypothesis

Umm well what sudo does is allow me to become root of the system. I am not root but its like an access window to be allowed to move around like a root user. With sudo, if i am allowed i should be able to do like anything i want cause im seen as a root user.

Experiment

I am just going to show the experiment right in the linux terminal screen.

Data

lab46:~$ man sudo
lab46:~$ sudo su -

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for dgirard3:
dgirard3 is not in the sudoers file.  This incident will be reported.
lab46:~$

Well there ya go xD

Analysis

Based on the data collected:

  • was your hypothesis correct? No it was not
  • was your hypothesis not applicable? Yes it was
  • is there more going on than you originally thought? (shortcomings in hypothesis) yes, i thought i could just use my name and password but i guess i must be listed as a superuser.
  • what shortcomings might there be in your experiment? Umm there is none, i just have no permission to do this so there is no more to do
  • what shortcomings might there be in your data? I believe i did everything right so noting :D

Conclusions

well a simple user of linux can not become a superuser. It kind of sucks cause i would like to have that power, but i cant. So if you try then you can not do it. Maybe one day me or someone else can be listed as the super user of a linux system.

Experiment 2

Question

Can you put a char in a int?

Resources

Class and matt haas :)

Hypothesis

I believe it can be done. I know a char holds a value in the ASCII code so i believe doing this will just pull out the value that char c holds.

Experiment

I will write a small program and execute it.

Data

  1 #include <stdio.h>
  2 
  3 int main()
  4 {
  5 int c='c';
  6 
  7 printf("Can you print a char as an int?\n");
  8 sleep(10);
  9 printf("Let's find out :D\n");
 10 
 11 printf("%d\n" ,c);
 12 return(0);
 13 }
 14 

Execution:

lab46:~/src/cprog$ ./yesno
Can you print a char as an int?
Let's find out :D
99

Analysis

Based on the data collected:

  • was your hypothesis correct? Yes it was
  • was your hypothesis not applicable? No it was :D
  • is there more going on than you originally thought? (shortcomings in hypothesis) Nope i knew what was going on
  • what shortcomings might there be in your experiment? I could have done the code wrong or something i dont know whats going on
  • what shortcomings might there be in your data? IOf it went wrong in the experiment then yes, but if not then no.

Conclusions

I knew there was a value in a char value i just was not sure if you were able to print it out and guess what :D you can. So this was pretty simple and it is very possible to do this.

Experiment 3

Question

Can a pointer be a void pointer?

Resources

My information comes from class :) so Matt Haas

Hypothesis

I think it can be because i have heard and read that it is possible, i just have not seen it, so i am curious to whether or not it is possible.

Experiment

Now i know i can do a pointer program like so:

1 #include <iostream>
2 using namespace std;
3 int main ()
4 {
5  int firstvalue, secondvalue;
6  int * woo;
7
8  woo= &firstvalue;
9  *woo = 10;
10  woo = &secondvalue;
11  *woo = 20;
12  cout << "firstvalue is " << firstvalue << endl;
13  cout << "secondvalue is " << secondvalue << endl;
14  return 0;
15  }

now it should just give me the values of 10 and 20, because it is pointing to them.

1 #include <iostream>
2 using namespace std;
3
4 void increase (void* data, int candy)
5 {
6  if ( candy== sizeof(char) )
7  { char* mountain; mountain=(char*)data; ++(*mountain); }
8  else if (party == sizeof(int) )
9  { int* no; no=(int*)data; ++(*no); }
10 }
11
12 int main ()
13 {
14  char a = 'x';
15  int b = 1602;
16  increase (&a,sizeof(a));
17  increase (&b,sizeof(b));
18  cout << a << ", " << b << endl;
19  return 0;
20 }

This is a void pointer at work. Just run this code and a value of y and 1603 should appear.

Analysis

yes my hypothesis was right, you can have a void pointer. You just need to have another pointer so it has a concrete data point to deference too. Voids can go from int to float easily but if you want to dereference it, you cant cause it doesnt have that concrete data type that is needed. However i feel as though i much rather see this kind of thing in a real program, like a program related to something. I just dont know what i would make it do or what for so for now i will leave it at that. I feel as though as this was a good hypothesis and no shortcomings were found except when i was looking at this code. It is just weird how it works at times, i just cant fully grasp it. I know what is happening, its all just an odd feeling i guess.

Data

This was done in the experiment.

Conclusions

In the end i basically knew that this could be done because i looked it up on google after i asked this but seeing work on linux and working out showed me that this stuff is possible to do at home and anyone can do it. Look up sample and work with those, manipulate them and just lay. When you play, you learn. I feel this isomething that is important to learn for the C language.