|
One student wrote asking about Assignment 1. Others might be having similar
problems. This might be more than you want to hear, but I hope it helps.
I have gotten SSH to run and have signed in to morbius.
Good
but I am unfamiliar with the UNIX environment.
If you sit in front of a machine running Unix, it probably has a modern
graphical user interface that is vaguely familiar. Mac OS X is really Unix,
for example. The challenge here is that we often do NOT sit in front of the
Unix machine. Rather, we are accessing a server remotely and must do
everything through a command line interface. In many ways, the command line
is more powerful, but there is MUCH to learn.
You need to learn at least a few necessary commands. For example,
ls |
Lists the contents of the current directory
Somewhat equivalent to Windows Explorer |
ls -al | Lists more details about the contents of the
current directory |
mkdir dirName | Created a new subdirectory
Similar to File | New | New folder | dirName |
cd newDir | Change current directory |
vi fileName | Simple character-oriented text editor (VIsual) |
man command | Gives help on a command |
etc. | |
You can learn about Unix commands from any of MANY good Unix tutorials. In
your favorite search engine, type "unix tutorial," and find one that speaks
to you.
In particular, I do not understand the section of
the lecture notes dealing with the "bash_profile."
Besides the Unix commands, over the semester, you will need to learn some of
how Unix works. Some of the functionality of Windows was derived from Unix
years ago, but is hidden behind the GUI. Using the command line, we need to
know more. Hopefully, eventually, we can accomplish more.
Both Unix and Windows use a PATH environment variable to tell the operating
system where to look for programs to execute. In a GUI environment, icons
and file associations (which program is started when you double-click) use
full path names (C:\Program Files\...) to find the correct executable. From
the command line, whether a DOS command box or a Unix command window, you
CAN type the full path, but you would rather not. You'd LIKE to say "gcc,"
for example, and have the operating system find the correct executable.
The PATH environment variable is stored in an operating system table, along
with several other environment variables. In a DOS command box or a Unix
command line, you can type "env," and you'll see the contents.
When you type a command on the command line, e.g., "gcc ..." the command
processor we discussed briefly in Chapter 1 successively looks for a gcc
executable in each of the directories listed in your path. In Windows, your
PATH includes C:\Windows and C:\Windows\System (and many others) so the
command interpreter can find the usual Windows commands.
When you compile a program, you want to be able to run it easily. You want
to type the name of the program you just compiled, and have it run. Hence,
you want the name of the directory in which you are working to be in the
PATH variable, so the command interpreter finds your newly compiled program.
By default, the current directory is NOT in the PATH, so you have to put it
there.
PATH is defined in the file .bash_profile (the leading period is VERY
significant). .bash_profile is one of several scripts that are always run
for you when you log in. Windows uses similar autoexec.bat and system.ini
files, if present. Since you want the current directory to belong to your
PATH, you do that by editing your .bash_profile
What am I supposed to do to this file and how do I do that?
PATH is defined in the file .bash_profile (the leading period is VERY
significant). .bash_profile is one of several scripts that are always run
for you when you log in. Windows uses similar autoexec.bat and system.ini
files, if present. Since you want the current directory to belong to your
PATH, you do that by editing your .bash_profile
In the file .bash_profile, you want to change the line
PATH=$PATH:$HOME/bin
to read
PATH=$PATH:$HOME/bin:.
There are many ways to accomplish that. I recommend editing, using the text
editor vi
What does "vi help: hjkl; Aoi; <esc>; :q!; ZZ" mean?
I have tried entering "vi help: hjkl," but it brings up a bunch of
empty lines, and does nothing till I enter ":q!," which takes me back to the
command line. "ZZ" does nothing, as far as I can tell.
Vi is a character-oriented editor. That means that what you SEE on the
screen is the text of your file. Vi was the first widely available editor
that showed more than one line of text at a time. You tell vi what to do by
typing characters. Almost every character is a command that causes vi to do
something. An old Unix joke is to open vi, type your name, and see what
happens, because each key you press is a command.
Fortunately, you do not need to know very many of those commands. The line
vi help: hjkl; Aoi; <esc>; :q!; ZZ
is intended to offer VERY limited help in using vi in the sense that in
class, I demonstrated what each one of those keys does:
Move cursor:
h Move cursor one character left
j Move cursor one character down
k Move cursor one character up
l Move cursor one character right
Enter text:
A Enter a mode to insert (type) characters at the end of
the current line
o Open a new line on which to insert characters
I Insert characters at the current cursor location
<esc> Exit character insert mode
Leaving vi:
:q! Quit without saving
ZZ Save and exit
Hence, to change the line
PATH=$PATH:$HOME/bin
to read
PATH=$PATH:$HOME/bin:.
Open the file to edit (note period):
vi .bash_profile
Move the cursor to the correct line:
j (as many times as necessary)
You want to add to the end of the line:
A
Enter the new characters:
:.
Leave the character insert mode:
<esc>
Save and exit vi:
ZZ
The danger of a "Here are the keys to press" instruction is that as soon as
things do not go exactly as you expect, you may be lost. I recommend you
learn a FEW vi commands. If you do any server work, the day will come, I
guarantee you, where knowing vi will save your ass.
Also, I cannot do the "cp -r ~corlissg/COEN183/osc7e-src/* " command. When I
try, I get the following error message: "cp: cannot stat
`/home/corlissg/COEN183/osc7e-src/*': Permission denied."
How can I fix this?
Finally, how do I provide access to the COEN183/hw03 directory that I created?
What is the "chmod" stuff, where do I get it (or how do I create it), and
where does it go?
Let's back up and consider what you are trying to accomplish.
I assume you are familiar with Windows folders and use them to organize your
work. "Folders" represent the graphical user interface conceptual model of
directories and subdirectories. MS DOS version 1.0 had no directories
because all files were stores on small floppies (5 1/4"). With MS DOS 2.0
(I think), Microsoft adopted the Unix concept of directories as we know them
today. When Windows was introduced, Microsoft introduces the folder icon,
hoping to make the concept easier to understand. Unix directory separator
is "/" vs. "\" in MS DOS. That might have been an intellectual property
issue, for all I know.
A portion of the directory structure on eng-feta is
/home
corlissg
COEN183
osc7e-src
chap3
jharman
each class member
In your account, I require your homework be organized
jharman
COEN183
hw03
whatever files for HW 3
I recommend that you make your own copy of the examples from the book:
jharman
COEN183
hw03
whatever files for HW 3
osc7e-src
chap3
chap4
. . .
To accomplish that, after you have finished editing your .bash_profile,
create the subdirectory COEN183:
mkdir COEN183
Change directory to make that your current directory:
cd COEN183
Create the subdirectory in which your homework will eventually go:
mkdir hw03
Create the subdirectory for the book's examples:
mkdir osc7e-src
Change directory to make that your current directory:
cd osc7e-src
(Wild cards work, provided the choice is not ambiguous, so you could have
said cd osc*)
Copy (recursively, meaning to include all subdirectories) the book';s
examples from my account:
cp -r /home/corlissg/COEN183/osc7e-src/* .
(the final period is critical. It says copy to HERE (current directory).)
Change directory look at Chapter 3:
cd chap3
In practice, you'll probably want to download all the
book's examples (protected) to
make it easier to browse around.
Alternatively, here is a
ZIP file (protected) of all of them at once.
If you have trouble with the command
cp -r /home/corlissg/COEN183/osc7e-src/* .
I suggest you download the full set to your local machine
since you probably want them anyway. Then upload just the ones you need
from your local machine to eng-feta.
I feel like I must have missed a day where you explained all
this, but I haven't skipped a class yet -- I can't imagine what kind of shape
I'd be in if I
had.
It's not terribly easy to do that, though, when I have never used or been
taught either the programming language or the operating environment that we
are required to do this assignment with. I realize that it's not your fault
that I've never used or been taught these things, but any help you can provide
me in the way of detailing how to best go about doing this homework assignment
would be greatly appreciated.
Fully understood. There are three alternatives:
- You've learned it before
- You learn it yourself
- I teach you
I HOPE most of the material in the class is not #1, or you are wasting your
money. I hope your goal, besides graduating, is to learn something.
In the LONG run, #2 is the goal. That is, Marquette should help you figure
out how to figure things out for yourself, because that is what your boss
will expect. By this point in your career, I hope that you can figure out a
lot of computer-ish stuff on your own, or with help of some friends.
#3. That's an option, when necessary. I DID go through the steps above in
class, but it was VERY quick. One of the dangers of this computer stuff is
that every key stroke matters. If there is ONE character you copy wrong,
the whole thing blows up.
In a class like this one, I hope for #2 in many things, but #3 is available
and acceptable. I hope this message has helped accomplish that.
How can I access the include files we need (sys/types.h, sys/ipc.h,
sys/msg.h)? I'd like to see if any of those will help me understand what
msgsnd() and msgrcv() do.
On a Windows box, I hope you'd use
Windows Explorer | C:\ | Search | types.h
On eng-feta, go to the root:
cd /
Find:
find -name types.h
You might want to learn some parameters of find:
man find
Alternatively,
find -name gcc
Then look for a subdirectory include
However, the *.h files give the signatures, not the semantics.
Also, I want to know if it's ok for me to alter the
> "typedef struct msgbuf" arguments. In the message_send.c and message_rec.c
> examples, "char mtext[MSGSZ]" is used, and I know I need to send integers.
- It satisfies the assignment to send the integers as characters.
- Yes, it is better to alter the typedef, but beware. There are surprises.
I haven't been able to get the parent and child processes to execute
concurrently. As it is right now, the producer executes, then the consumer
executes. The address locations of the data sent to msgbuf match up with the
address locations of the data received. However, the data I store in the
addresses is different from the data I received in the same addresses. Do you
have any advice?
The producer and the consumer do not really execute concurrently. They go through the run, wait, ready states. It MAY be that your producer is fast enough that it does all its work in one time quantum. To achieve the behavior you expect, you may need to put a delay in the producer. There are "better" ways, but something like
for (i = 0; i <= 100000; i ++) x = sin(2.6*x-3.8);
works. 2.6 & 3.8 are just arbitrary magic numbers, hoping to avoid the fixed point 0 = sin(0). The point is just to waste some time. Later, we'll look at the operating system call WAIT()
File protection
In any multi-user file system, you should be able to protect your files fromviewing ot tampering by other users. Hence, each directory
and each file has protections associated. In order that I can grade your homework, the file protections must let me in.
On eng-feta, from your home directory
Back up to the /home directory which contains your home directory:
cd ..
Look to see what is there:
ls al
You will see that your permissions are rwx------
Change
chmod 755 bhall
Check
ls al
You should see privileges on bhall as rwxr-xr-x
Then you should use the same approach to double-check all your subdirectories
Subdirectories should be rwxr-xr-x (chmod 755)
Text files (e.g., source) should be rw-r—r-- (chmod 644)
Ethics
Historically, UNIX has fostered an open environment in many ways. It is designed
to facilitate cooperation. On many systems, the systems defaults are that all
directories and all files are readable by all.
The common practice for authors is that you change protections on files and directories
that really deserve to be protected and not worry about the others.
The common practice for others is that you NEVER, NEVER, NEVER look in another
user's directories or files without permission. If you leave your house unlocked,
someone can walk in and take things, and it is still stealing. While you can,
you DON'T.
I assert that as students in this class, you are giving me permission to look
in your homework directories. That implicit permission sometimes allows me
to offer debugging assistance, when I think that is wise. If you have reservations
about my looking, or are nervous about your classmates violating the common
practice described here, you may protect your work, but then the responsibility
is yours to communicate your homework to me in a manner that is not TOO inconvenient
for me.
One engineer I knew at Sun told me that in his group, they never protected anything,
but if anyone typed
cd /home/someoneElsesUserID/...
by the time they hit the return key, a security guard would be at their door to escort them permanently from the building.
| |