Difference between revisions of "Subjects/unx511-043"

From CDOT Wiki
Jump to: navigation, search
(Created page with "== [http://www.senecac.on.ca ] [http://cs.senecac.on.ca ] <center>- UNX511 -</center> == == <center>UNIX System Programming</center> == UNIX, the operating system of c...")
 
(No difference)

Latest revision as of 17:01, 15 May 2022

[1] [2]
- UNX511 -

UNIX System Programming

UNIX, the operating system of choice for much of the Internet, is the most versatile non-platform-specific, general-purpose computing environment available. This subject explores UNIX at a technical level. The primary focus will be system and network programming using C. Students will also learn advanced scripting techniques and the use of development tools and utilities. Prerequisites: OOP444 or CBL344 or RPG444 or RPG445 or BAC344 or OOP344 During this semester you will have to complete about 10 labs, 3 assignments, 1 midterm test, and 1 final exam. This is the place where I will post information you will need. Please visit this page often. Course Outline

Text

  • Understanding Unix/Linux Programming: A Guide to Theory and Practice
  • by Molay, Bruce
  • Published by Prentice Hall
  • ISBN - 0-13-008396-8

Assignment Expectations

  • [../expectations.html How to Prepare Assignments?]
  • [../resubmit.html How to Resubmit Assignments?]

Laboratory List

  • [lab01.html Lab #01]
  • [lab02.html Lab #02]
  • [lab03.html Lab #03]
  • [lab04.html Lab #04]
  • [lab05.html Lab #05]
  • [lab06.html Lab #06]
  • [lab07.html Lab #07]
  • [lab08.html Lab #08]
  • [lab09.html Lab #09]
  • [lab10.html Lab #10]
  • [lab11.html Lab #11]
  • [lab12.html Lab #12]

Assignment List

  • [ass01.html Assignment #1]
  • [ass02.html Assignment #2]
  • [ass03.html Assignment #3]

Lecture topics, notes & other stuff

  • April 6, 2004
    • Today we walked thru the client/server programs from lab #8. Please download [lab8.tgz this tar ball] and examine, compile and run the code.
    • I also, once again, explained the two client/server models - one uses fork() and the other uses select()/ioctl() functions.
    • I made some minor modifications to assignment #3. Please get a fresh copy.
  • March 30, 2004
    • Today we walked thru lab #6.
    • I also explained how Unix signals work in more detail. Only signal 9 (SIGKILL) cannot be caught. Lab #6 uses SIGPIPE in the server program to know when (if) the client breaks the connection.
    • I also introduced two new C functions, wait() and execl(). Here is a [a31.c short example] program.
    • And I explained how this [a32.c program] uses signals. In BASH we use the kill command to send a signal to another process.
    • Finally, we looked at assignment #3 again. It's now version 1.0 so start coding.
  • March 23, 2004
    • Today we did a walkthru of lab #6. The important C functions to study include socket(), bind(), listen(), accept(), and connect(). Of course you should also learn to use read() and write().
    • I also explained the concept of named and un-named pipes. We can use the Linux command, mkfifo, to create a named pipe. To create an un-named pipe, we use the pipe() function inside a C program.
    • We wrote a C program, [a23.c a1.c] which demonstrated how a pipe can be used to send information from one process to another.
    • Finally, I explained assignment #3. It's still a beta assignment so hold off on the programming until next week. We need to get the specifications correct and complete. Meanwhile, Troy sent in these two links about the Prisoner's Delemma. If anyone finds other interesting links please forward them to me and I'll post them here.
  • March 16, 2004
    • Returned midterm test.
    • Students completed course evaluation.
    • I began to discuss the fork() function. Some examples I used include [a1.c a1.c], [a2.c a2.c], [a3.c a3.c] and [a4.c a4.c].
    • The first thing to know about forked processes is that, in many cases, it's impossible to predict which will complete first; the parent or the child. To be safe the parent should always wait for the child to die first.
    • I explained how Linux processe form a hierarchy, similar to the file system. Every process has a parent except the first one which is the init process. The fork() function creates child processes. Child processes should complete before their parents. Child processes without parents are called zombies. We use the ps command to view the process table and kill to distroy processes.
    • "Copy on Write" is the way Linux duplicates the memory of the parent to the child. It only does so when the child attempts to "write" new data to RAM.
    • Assignment #2 is due Friday, March 19, 2004.
  • March 9, 2004
    • Did a 1 period review for Friday's test. Please study regular expressions, state diagrams, bash scripts and awk. The test will be open book but no electronic aids are allowed.
    • In the second period I discussed the client/server programming models used in Unix environments; single server vs multiple servers. For the multiple server model we use the fork() function to duplicate the server. In the single server model we must consider unblocked reads so the server can cycle through all file descriptors; one per client.
    • There will be no new lab Friday.
  • March 2, 2004
    • Study week (March break).
  • February 24, 2004
    • Today I explained lab #5 (curses program). You'll need to understand this in order to do assignment #2.
    • I began discussions on IPC (Inter Process Communications)
      • shared memory
      • signals
      • semaphores
      • pipes
      • sockets
    • I explained the relationship between ports and file descriptors.
    • I also discussed the Unix client/server model.
    • Returned assignment #1. You can still get a C if you submit assignment #1 this Friday.
  • February 17, 2004
    • Today I explained the C program we used in Lab #4. I discussed how the program is stored in RAM (code, stack, static, heap areas). For every malloc() you need a free(). In C++, for every new you need a delete. Java uses garbage collection so programmers have less control over RAM.
    • Some commands I used included strings, file, ldd, ar.
    • I explained the difference between static libraries (*.a) and shared objects (*.so). In the Windows world shared objects are known as Dynamic Linked Libraries (DLLs).
    • I explained where Linux libraries can be found (/usr/lib, /lib). I also used the cc command to compile a simple C program using the pow() function from the math library (libm.a).
    • We also looked into C header files (/usr/include). Header files contain no executable code, just macros and definitions.
    • If you haven't handed in assignment #1 yet then you can hand it in on Friday (maximum B grade). After Friday, you will be going for a C on assignment #1.
    • MIDTERM TEST: is scheduled for March 12, 2004.
  • February 10, 2004
    • Today we discussed assignment #1: how to solve it and how to prepare your report. If you missed this class please ask your classmate for the notes.
    • I also did walkthru's of several shell script examples which can be found at Les Czegel's web site.
    • HOMEWORK: Run and understand all script examples shown on Les' page.
  • February 3, 2004
    • Today's class concerned terminal I/O in Unix. I explained how the /etc/termcap file (database) works and the migration to the terminfo database. I used the tic command to compile a termcap file into a binary terminfo file. We can use the infocmp command to reverse the process. I explained how "dumb" terminals intrepret control codes and the importance of the TERM environment variable.
    • I assigned octal codes to variables using the command a=$'\033' which assigns ESC (octal 33) to the variable a. To see all ascii codes use the man ascii command.
    • We took a break when the fire alarm went off.
    • I used the tput command to position the cursor. i.e. tput cup 12 30
    • Finally, I showed how we can make a manual page. First take an existing page from say, /usr/share/man/man5/passwd.5.gz, and unzip it into your own directory. Then edit it with vi. Check it with the groff command like this:
	groff -Tascii -man passwd.5 | more

If it looks good then rename it and gzip it and copy it to the proper volume of the manual.

    • HOMEWORK: Read the manual pages for the commands we used today.
  • January 27, 2004
    • If you want to volunteer at this spring's RealWorldLinux Conference then fill out the form at Seneca's Linux Club.
    • Today I discussed assignment #1 which is due on February 13. I showed an example shell program that uses non-canonical input. If you missed the class then ask one of your classmates for the code or come and see me.
    • I also discussed terminal settings using the stty command. For example, we can change CONTROL C to some other character, or we can turn off echoing of typped characters. Also, stty sane may bring back some sanity to your terminal session.
    • Finally I showed a sed program that removes C style comments from a C program.
    • Lab #2 is now on-line.
    • HOMEWORK: Read the manual page about the stty command.
  • January 20, 2004
    • Intro to sed, the command-line stream editor.
	SYNTAX: sed [address]command file(s)

	COMMAND EXAMPLES: s/john/JOHN/g 
		 	  /^$/d 
			  /John/i\
			  Toronto
	ADDRESS EXAMPLES: /john/
			  3
			  3,12
			  2,/john/

    • Intro to awk, the command-line file manipulation tool.
	SYNTAX: awk BEGIN{...}...{...}END{...} file(s)
		BEGIN, SELECTION, ACTION, END

    • Intro to grep, the search tool.
	SYNTAX: grep RE file(s)

    • I also explained how quotes are used by the shell.
      • Single forward quote: blocks all substitutions.
      • Double quote: blocks some substitutions, allows others.
      • Backslash: same as 1 but only quotes the following character.
      • Single backward quote: evaluates a command. This has been replaced by $(...)
    • I explained several examples from lab #1.
    • HOMEWORK: Read all you can about awk, sed and grep. There are many examples in your UNX122 text and dozens of on-line tutorials you can find thru google.
  • January 16, 2004
    • Gave a brief introduction to regular expressions.
    • Compared regular expressions to arithmetic, algebraic and boolean expressions.
    • Showed how to draw state diagrams.
    • Explained how to make a transition table.
    • Also, used a simple RE example and wrote the C code to validate matching strings.
    • Showed students lab #1 and wrote a short shell command to generate random records which can be used for testing.
    • HOMEWORK: Read the appendix in your UNX122 text regarding regular expressions and continue reading about awk and sed. In the next class we'll cover these tools in more detail.
  • January 13, 2004
    • Introduction to the course, including teacher policies, assignment expectatiions, evaluation methods, and course outline walk-through.
    • Brief history of Linux.
    • The Unix philosophy, use small tools together to solve large problems.
    • Concept of "kernel space vs user space".
    • Concept of "context switch" in multitasking environments.
    • Using the "time" command to see how long a program takes.
    • tab-tab to list all commands and script to capture the list.
    • Concept of "internel vs external" Linux commands. i.e. ls is external while cd is internel.
    • Open source software means "freedom" not free cost.
    • HOMEWORK: Please read about awk and sed in your UNX122 text.
    • Our lab on Friday will be a lecture and not a lab. The first lab will be on January 23.
    • Get info on Linux Club if you're interested.

[../index.html ]