Chapter 3 Flashcards

(42 cards)

1
Q

What are the three purposes of operating systems?

A

Provide reliable and efficient concurrent execution of multiple
processes.

Provide mechanisms for inter-process communication

Simplify application development

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Define a process.

A

Instance of running program that includes all system resources used for that program. Has a unique PID. Processes only interact with each other through kernel (ecall instructions).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How are processes created using fork?

A

fork() system call creates a copy of the calling process and assigns it a new PID. Both the parent and the child processes continue from the same fork() call, but in child fork() returns 0, in parent it does not.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the wait system call do?

A

wait(int *status)
Puts calling process to sleep until one of its children processes terminates with exit(status)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does the exec command do?

A

exec(prog, arguments[]) - replaces the running program in the calling process with the program in the file prog. first argument is name of file, subsequent arguments are command line arguments.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Syntax for opening, reading, writing into a file.

A

fd = open(“filename”, flags, permissions)
write(fd, message, number of bytes);
read(fd, data, num);
close(fd)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the flags for the open command?

A

O_RDONLY (read only)
O_WRONLY (write only)
O_RDWR (read and write)
O_CREATE (whether to create if not there)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Pipe syntax.

A

int p[2];
pipe(p);
read from p[0]
write to p[1]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Syntax of simple commands in bash.

A

command arg1 arg2 … argN

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Distinguish between operands and options.

A

Operands are object arguments
Options modify default behavior of the command.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What do \, ‘ and “ do?

A

\ removes special meaning of following symbol.
‘ removes special meaning of all symbols surrounded by them.
“ removes special meaning of all symbols surrounded by them except $, \ and ``.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How are non-built in commands run?

A

If the command specified by the user is not a built-in command, the shell tries to find an executable file in the file system with the name matching the command and runs it as a child process using exec().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does pwd do?

A

Print the full name of the current working directory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How does one run an executable file from the current working directory?

A

./exeName

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What do the nano and cat fileName commands do?

A

nano -> starts a text editor
cat fileName -> displays the contents of the file with the name file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Inside the nano text editor how do you save changes.

A

Ctrl - O to write out data
Ctrl - X to exit

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How do you copy, move and delete files in UNIX?

A

cp foo bar -> copy the contents of file foo into file bar (create if doesn’t exist)
mv foo bar -> move the file foo into bar
rm foo delete file foo

ln foo bar (create a hard link bar to the file foo)

18
Q

How do u make and remove directories?

A

mkdir dirname = create directory with the name dirname
rmdir dirname = delete directory with the name dirname

19
Q

To instruct shell that process should take input from file, write output to file and output error messages to file, syntax.

A

command arg1 <inputFile>outputFile 2>errorFile (arg2 ... argN)</inputFile>

20
Q

When we want to disregard output data what can we do?

A

Redirect output stream to /dev/null

21
Q

What is syntax to send output and errors to same file? What does&raquo_space; do?

A

command >outputFile 2>&1

Using&raquo_space; means it appends instead of overwriting.

22
Q

How can a string be passed as a command line argument?

23
Q

Use bc to calculate 2^128.

A

bc «< “2^128”

24
Q

I want to pass as input everything in a file until a particular word.

A

«word
/
/
contents we want to append
/
/
word

25
What does find and wc commands do? Give an example using both.
find generates list of all C files in the current directory on separate lines. wc (prints number of lines, words or bytes depending on options) find . -name "*.c" | wc -l . (signifies current directory and all sub-directories) -name (is what find is looking for and "*.c" the ending name. -l tells wc to count the number of newline characters. | pipes the output on the left into the right.
26
What does tr set1 [set2] do? How can tr access all whitespace, upper or lowercase letters?
Replaces character listed in set1 with corresponding character in set2. "[:blank:]" "[:upper:]" "[:lower:]"
27
What does uniq file 1 file2 do? What does sort -u file do? What does cut -b a,b,c do?
uniq discards all but one of successive identical lines from standard input and writes to standard output. sort concatenation of all files. -u removes duplicate lines. cut -b takes bytes a,b,c where a,b and/or c could be ranges and drops all other bytes.
28
What do commands head and tail do?
Print first / last 10 lines from file respectively.
29
What do more, less, tee do?
More and less ask user if they want to keep reading file after certain length. tee outputs to SO and file.
30
How are shell variables declared in bash? What does set do?
VariableName=VariableValue Displays all shell variables
31
How can the result of a compound arithmetic expansion be computed (e.g. display 1 + 3)?
echo $((1+3))
32
How does brace expansion work?
Arguments that contain optional parts -> my_file.{c, h} -> replaced with all possible combinations resulting from substituting optional parts into the argument.
33
How can a shell script be run?
chmod +x my_script //marks it as executable ./my_script to run
34
What does every bash script begin with?
#!/bin/bash
35
How is a for loop implemented in bash?
for var [in words]; do commands; done
36
Syntax for reading into a variable in bash?
read varName
37
Give basic case syntax for bash.
case var in option1 | option2) commands;; option3) commands;; *) commands;; esac
38
How can the exit status be accessed?
$? command
39
Give if/while syntax in bash.
if [ "$A" = "1" ]; then echo "A is 1" else echo "A is not 1" fi while ["$A" = "1"]; do commands; done
40
What is copy-on-write?
Memory optimization technique that minimizes the time spent copying memory during a fork() and exec() sequence. Child and parent process share same memory pages until one of them attempts to modify that memory then copy is made.
41
What is transaction logging?
Logs all changes in a system where data consistency and recovery are critical such as databases. 1. A command either runs fully or not at all 2. If it runs it is permanent 3. Changes made recorded before change actually implemented.
42
What is lazy memory allocation?
Memory allocated only when used (i.e. when variable accessed).