COMP 206 Lecture Notes - Lecture 8: Standard Streams, System Call, A.Out

73 views10 pages
COMP 206 Lecture Notes
Lectures (1-8)
Software System: A collection of specifications agreed upon and coded by several
programmers such that multiple elements work together effectively .
Kernel: Schedules processes and manages users . Login, task switching etc.
Kernel space: An interface to OS functionality (system call) virtually mapped in to every process.
Bash: A type of shell. Allows programming a computer through interpreted commands.
Heap: Dynamically allocated memory controlled by the program.
The Stack: Storage for local variables and function parameters associated with each function
call. Controlled by the OS.
Shell: The shell is a command interpreter . It turns text that you type into actions.
- It’s also a programming language and can script.
- It’s also a program that reads from standard input.
Gcc: Produces executable code from files.
Bios: The very first code to run when a computer receives power.
Bootloader: Loads the operating system and begins its execution, (In Linux its GNU)
All we need to know for exams! (Boot order) : BIOS → Bootloader → Kernel
File System: Defines the way the disk drive is formatted. The FAT
Directory Tree: The concept that every directory has a parent, except for “/” (root) which is at the
top.
Bin: Means binary directory or programs.
Standard Input (STDIN): The shell uses STDIN to figure out what command you’ve run.
- Basically what you type in on your keyboard.
- To end STDIN in Linux you need to input Ctrl-D.
Standard Output (STDOUT): STDOUT displays what the command does.
Unlock document

This preview shows pages 1-3 of the document.
Unlock all 10 pages and 3 million more documents.

Already have an account? Log in
Important Linux Paths:
- “/” is the root of the file system. Every other file falls below “/”
- “~” is the current user’s home directory
- “.” means right here when it starts a path
- “..” means the parent directory
Running a program:
- Type the program’s name followed by command-line arguments.
- $ ls -al /bin
-ls is the Program Name (always needed)
--al is the First Argument (this time a flag or option)
-/bin is the Second Argument (this time a file name)
Wild Card Characters:
- The special character *
-* matches anything.
- If you give the shell * by itself the shell will remove the * and replace it
with all the filenames in the current directory.
- a*b ” matches all files in the current dir that start with a and end with b.
Input and Output Redirection:
- To tell the shell t o store the output of your program in a file, follow the command
line for the program with the “>” character followed by the filename:
- $ ls > lsout.txt
- Creates a file named lsout.txt and put the STDOUT of the ls in that file.
- To tell the shell to get STDIN from a file, use the “<” char:
- $ sort < nums.txt
- Would sort the lines in the file nums and send the result to STDOUT.
- Do both!
- $ sort < nums > sortednums
- Takes input from nums, sorts it, and sends the output to sortednums.
Output and Output Append:
- The command $ ls > foo.txt will create a new file named foo (deleting any
existing file named foo).
- If you use >> the output will be appended to foo.
Pipes:
- A pipe can be used to hold the output of one program and feed it to the input of
another.
- To ask for a pipe, separate 2 commands with the “|” character, like so:
-ls | sort or ls | sort > sortedls
-ls | sort pipes the input of ls to sort. So now your ls that prints on your
terminal is sorted.
Unlock document

This preview shows pages 1-3 of the document.
Unlock all 10 pages and 3 million more documents.

Already have an account? Log in
Git: A distributed version control system.
Segmentation Fault: You’ve tried to access some memory which you’re not allowed to access. If
you haven’t typed in an argument, but you try to access it, C will tell you that you can’t.
C Function Properties: Name must be unique (can’t overload functions), pass arguments by
value, and define a local scope for variables.
Const:
- const int array_length = 10;
- This means that array_length is defined once and is not allowed to be changed.
Pre-processor replacement:
- #define array_length 10;
-#define is like find/replace. All instances of array_length become 10.
-#include copies the contents of the header to that location.
Arrays in C:
- Initializing arrays:
- int num_args = argc - 1;
int array[num_args];
for(int pos = 0; pos<num_args; pos++) {
array[pos] = atoi(argv[pos+1]);
}
- Kind of similar to Java, but in C its (type name) (var name)[size] .
- Outputting the array to the terminal:
- for(int pos = 0; pos < num_args; pos++) {
printf(“Element %d is %d.\n”, pos, array[pos]);
}
- Arrays can’t change size and take a “slot” in memory.
Strings in C:
- C Strings are pointers or arrays of char data.
- At the end of every properly created String, there is a special character (exactly
zero) that says “this is the end of the string”. This character is \0 .
- Double quotes “ “ in C mean “string constant”, it puts the \0 on at the end.
- Because of C’s pointer/array duality, we can often use the types interchangeably:
- int main(int argc, char**argv)
- //Is OK too along with char* arg[v]
Unlock document

This preview shows pages 1-3 of the document.
Unlock all 10 pages and 3 million more documents.

Already have an account? Log in

Document Summary

Software system: a collection of specifications agreed upon and coded by several programmers such that multiple elements work together effectively . Kernel space: an interface to os functionality (system call) virtually mapped in to every process. Heap: dynamically allocated memory controlled by the program. The stack: storage for local variables and function parameters associated with each function call. Shell: the shell is a command interpreter . It turns text that you type into actions. It"s also a programming language and can script. It"s also a program that reads from standard input. Bios: the very first code to run when a computer receives power. Bootloader: loads the operating system and begins its execution, (in linux its gnu) All we need to know for exams! (boot order) : bios bootloader kernel. File system: defines the way the disk drive is formatted. Directory tree: the concept that every directory has a parent, except for / (root) which is at the top.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents