Midterm I Flashcards

1
Q

What is the onion skin model of an operating system?

A

Users>Application programs>Operating System>Hardware

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

What are some functions of operating systems?

A

– Provides an interface between application programs and the hardware
– Hides the complexity of hardware interfaces from application programs
– Protects the hardware from user mistakes and programming errors (to prevent crashes)
– Manages the hardware resources of the computer systems
– CPU time, disk space, memory access, . . .
– Protects user’s programs and data from each other (security issues)
– Supports inter-process communications and sharing
– Provides resource sharing among users and processes

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

Who created UNIX?

A

Ken Thompson 1969

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

What was MULTICS

A

A multi-user OS developed by MIT, Bell Labs, and GE for the GE-645 system; a “computing utility”,
similar idea to “cloud”
(a) advanced capabilities, including security mechanisms
– segments instead of files/memory
– dynamic linking, hot-swapping of components
– hierarchical file system, multi-ring security
(b) relied on the special features of the GE-645
(c) was slow and expensive to run
– Ken Thompson wrote a game (Space Travel) which costed $75 dollars to play
(d) The hardware was not up to the demands of the software.

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

UNIX on PDP

A
– Ken Thompson, Dennis Ritchie, Rudd Canaday started talking about a system that had
1. a developer friendly environment
2. encouraged “fellowship among users”
3. file system for multiple users
4. was efficient and simple
– Implemented it on an old PDP-7, in assembly language
1. Wrote it on a GE system
2. Assembled it
3. Copied it on to paper tape
4. Carried to the PDP-7
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

When were pipes implemented in UNIX

A

When UNIX was rewritten in C, pipes were implemented then (1970-73)

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

Describe the 1980s UNIX wars

A

1980s Unix Wars
– Many companies (IBM, Bell, Sun, etc) developed their own versions of Unix; Xenix was available for PCs,
being licensed by Microsoft from AT&T
– Ceased to be free, lots of commercialization
– Not a good time for the hobbyist (or academic)
– Different flavours/versions emerged
– System V (AT&T) vs. BSD Unix (UC Berkeley)
– 1985 GNU begins development of a free Unix, except kernel; GNU’s Not UNIX
– 1991 Linus Torvalds develops the Linux kernel

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

Describe Linux

A

– 1991: Linus Torvalds announced the project
– Open-source, UNIX-like OS kernel
– Does not share code with UNIX
– Usable in 1992
– Essentially GNU/Linux
– Various distributions available: Fedora, Ubuntu, etc

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

Explain the concept of a pipeline

A

A pipe is a mechanism in which the standard output of one process is directed into the standard input of another process. A pipeline is a sequence of several running processes, where each process’s standard output is re-directed into the standard input of the next process. The first process does not have its standard input re-directed, and the last process does not have its standard output re-directed. The processes are executed concurrently

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

Unifying principles of UNIX (6)

A
  1. Everything is either a process or a file
  2. Pipes are used to connect output of one program to the of the next
  3. Process spawning and interprocess communication is well-supported, flexible, and cheap
  4. Communication between programs should be simple
  5. Cooperating programs don’t know about each other
  6. Programs are designed “to operate not specifically with each other, but with programs as yet unthought
    of” — McIlroy
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Notable UNIX features

A

Allows many users to access a computer system at the same time
– Shares CPU’s, memory, and disk space in a fair and efficient manner among competing processes (CPU time
is split in “slices”, typically 1/10 seconds)
– Processes and peripherals talk to each other even on different machines
– Provides a well-defined set of system calls similar to library routines
– Very portable

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

Define: File

A

collection of data (sequence of bytes) stored on disk (or other external storage)

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

Define: Program

A

a file containing machine code and data that can be loaded into memory and run

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

Define Process

A

Program that is loaded in memory and running

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

Define kernal

A

The kernel is the hub of the operating system. It allocates time and memory to programs, handles file storage, and
deals with many other tasks critical to the functioning of a computer. It also handles communications in response
to system calls

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

Define System Call

A

A system call is how a program requests a service from the kernel. A system call is usually
implemented as a library function with the same or very similar name. At the machine code level, a system call
usually works by preparing the appropriate parameters in the CPU registers and by making a special jump into the
kernel code

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

What is the shell

A

The shell is a text-based interface to the UNIX system. It is a command-line interpreter that interprets user commands
and arranges for their execution. It is usually assumed that a shell is text-based, but GUI (graphical user
interface) window managers act as shells in many ways, and are sometimes also called shells.
– A UNIX characteristic is existance of multiple shells (even Window managers); e.g.:
– Bourne Shell: sh, bash (Bourne-Again Shell); we will focus on this one
– Korn Shell: ksh
– C Shell: csh, tcsh
– Z Shell: zsh

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

what is a utility

A

A utility is a program with the same name as its command (example: clear, or date)

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

what is a command line argument?

A

– Utilities can accept arguments
– For example, date utility allows us to choose format of the output, as in:
date +%Y-%m-%d-%H-%M-%S

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

How do you access the manusal

A

you can access the manual using the “man” command. if you are looking for information on a particular program you can use “man clear” which would give you the manual page about the program clear

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

what are two important special characters?

A

Control-C (ˆC) is used to terminate a process

– Control-D (ˆD) is used to signal end of file

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

what are the standard IO streams for a UNIX program

A

stdin (standard input)
– stdout (standard output)
– stderr (standard error)

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

what does the command “cat” do

A

cat > file.txt will allow creation of a file. cat file.txt will print the contents of file.txt

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

How to log out of bluenose?

A

Ctrl-D

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

What are the 7 types of regular files?

A
  1. Regular files
  2. Directory files
  3. Buffered special files (block devices)
  4. Unbuffered special files (character devices)
  5. Symbolic links
  6. Pipes (named pipes)
  7. Sockets
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

Define: Regular file

A

Regular files: are files containing text, executable programs, graphics, video, and similar. These are the files
we usually think of by default under the name ‘files’. In a long ls output (ls -l), these files are indicated with
the character ‘-’.

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

What is a directory file

A

The directories that store groups of other files are also a type of files called directory files. In a
long ls output, these files are indicated with the character ‘d’.

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

What are buffered special files

A

are also called block devices. These files represent disk drives, USB keys and similar
in a direct access. They are called buffered because a buffer in memory is used in reading and writing them. In a
long ls output, these file are indicated with the character ‘b’.

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

what are unbuffered special files

A

are also called character devices, and represent devices such as terminal and keyboard.
Both, buffered and unbuffered special files are called device files. In a long ls output, these files are indicated with
the character ‘c’.

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

what are symbolic links

A

are references to other files. Using them, we can access existing files through a different
pathname (path). They are similar to shortcuts in Windows. In a long ls output, these files are indicated with the
character ‘l’.

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

What are pipes

A

are used for inter-process communication, and they are also called named pipes. This file type should
not be confused with pipes created between processes in a compound shell command. In a long ls output, these
files are indicated with the character ‘p’.

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

What are sockets

A

are used for inter-process communication, similarly to pipes. One of the differences is that sockes are
fully duplex-capable; i.e., processes can send data both ways, unlike pipes. Beside data, processes can also send
file descriptors using sockets. In a long ls output, the socket files are indicated with the character ‘s’.

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

What are pathnames?

A

Each file has a name
– Files can have the same name if they are in different directories
– Example: see bin in the previous figure
– To distinguish files with the same name, we use pathnames
– Pathname (or path) is a sequence of directories, finishing with a file name
– Directories are separated using character slash (/)
– Example:
/users/faculty/vlado/csci2132/lab1/HelloWorld.java

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

What is an absolute path

A

– Absolute path starts from root (initial slash /), examples:
/usr/bin
/users/faculty/vlado/csci2132/lab1/HelloWorld.java

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

what is a relative path?

A
Relative path starts from the current directory; examples (if the current directory is ‘vlado’):
csci2132
csci2132/lab1/HelloWorld.java
./csci2132/lab1/HelloWorld.java
../../visitor
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

Parts of a pathname

A

basename /home/ed/file.txt
basename /home/ed/file.txt .txt
dirname /home/ed/file.txt

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

path related commands

A

– ls paths — list directory contents
– pwd — print working directory
– cd path — change directory
– mkdir dirs — make directory(ies)
– mkdir -p paths
– rmdir dirs — remove empty directory(ies)
– mv path1 path2 — move or rename directory or file
– mv -i path1 path2
– rm paths — remove files but can remove directories with option -r; useful to consider -f and -i

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

what are some file manipulation commands?

A

– cat files — showing textual file(s) content
– more files — showing textual file content, paged
– head files — showing textual file content, first part
– tail files — showing textual file content, last part
– vi, emacs, pico, nano — file editors
– wc files — word count

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

What are Usernames and UserIDs

A

– Used to protect files and processes between different users
– Every user has a unique username, which is a text string
– Try command: whoami
– The system uses numeric userid, which we will call just userID (username is for string id)
– Try command: id -u

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

What is a Group?

A

Every UNIX user is a member of a group
– A user can be member of multiple groups, but one is effective for a process
– Each group has a unique groupname and groupID
– Command to list groups user is member of: groups
– Command for more complete information: id
– Each process, including shell, has one effective userID and groupID
– Each file is owned by one user and one group: file owner and file group

41
Q

What are the 3 file permissions?

A

user group other

42
Q

how to check file permissions

A

– Command: ls -l
– Note: a few more useful ls options: -a -t -r
– Example:
$ echo test > tmpfile.txt
$ ls -l tmpfile.txt
-rw-r–r– 1 vlado csfac 5 Sep 13 11:21 file.txt

43
Q

how to compile a java program

A

javac HelloWorld.java

44
Q

how to run a java program

A

java HelloWorld

45
Q

what does chmod do?

A

The command chmod is used to change file permissions, or in other words, the file mode bits. Its syntax is:
chmod mode files
where mode specifies the new mode-bit pattern for the files given in the argument files. One way is to give the
pattern explicitly, as in:
chmod 664 file.txt
where the number 664 represents in the octal base the new bit-mode pattern for the file file.txt. If we translate
the octal number 664 in binary, it is 110 110 100, so the new permission for the file are rw-rw-r–, or read,
write, and not execute for user, read, write, and not execute for group, and read, not write, and not execute for the
others

46
Q

changing owner and group of a file

A
– chown newuser file.txt
– chown -R newuser files dirs
– chgrp newgroup file.txt
– chgrp -R newgroup files dirs
-R is used for directory recursive change
47
Q

Changing effective groupID and userID

A
– newgrp newgroup
– changes into newgroup (logs into new group)
– su newuser
– changes effective user
– needs to be superuser (root user)
48
Q

How to redirect output

A

– Remember what we learned about: stdin, stdout, stderr
– Redirecting the standard output of a program into a file:
command > filename
– Creates a file (filename) if it does not exist
– Example: ls lab1 > listing
– Important: ‘>’ redirection deletes previous file contents
– To append a file with new content use ‘»’
– Example: ls lab1&raquo_space; listing
– Creates a file (‘listing’) if it does not exist, as well

49
Q

how to redirect input

A

Redirects the standard input from a file into a process
– Useful in testing
– Syntax: command < filename
– Example: sort < names.txt
– sorts names in a file names.txt and prints out
– Example 2: sort < names.txt > names-sorted.txt
– Example 3: mail csusername < HelloWorld.java
– Example 4: mail full@email < HelloWorld.java

50
Q

how to redirect errors`

A
– Standard error output is not redirected by >
– Syntax (bash specific):
command 2> filename
– Cannot be a space between ‘2’ and ‘>’
– Example: rm x 2> error
– If file x does not exist, it will produce an error message
– >> can be used to append output:
command 2>> filename
51
Q

what are wildcards

A

– Used to specify multiple filenames
– Makes use of “wildcards”; i.e., metacharacters expanded by the shell
– Some wildcard types:
– ?: matches any single character
– *: matches any string, including empty string
– […]: matches any single character in the set
– [!…]: any character except characters from the set

52
Q

what are some file substitution examples

A

– [0-9]: any digit between 0 and 9
– [a-zA-Z]: any English alphabet character
– [unix]: matches either ‘u’, ‘n’, ‘i’, or ‘x’
– ls ˜/csci2132/lab1/.java — list Java files
– ls .???? — list all files with 4-character extension
– ls lab[1-9] — list all files with the name consisting of word lab and a digit from 1 to 9
– ls [!0-9]
— list all files which name does not start with a digit
– cp lab1.bk/
.java lab1/ — copy Java files from one directory to another

53
Q

What is an inode number

A

Every file has a unique inode number. A directory is a file containing a table of pairs (inode number, filename),
where each pair corresponds to a file in the directory. There is one system-wide inode table, and inode numbers
are indices into it.
In this way, the execution of commands such as ls -l that retrieve information regarding files in a directory can
be efficient. This is a nice model that is effective and logical—a good example to follow when we design complex
systems.

54
Q

how to reveal inode numbers

A

To reveal file inode numbers, we can use the option -i in command ls. For example, the command:
ls -lid tmp
may give an output like:
84492732 drwx—— 2 … tmp
where the first number (84492732) is the inode number of the directory tmp, which is a file. The option -d is used
in the command ls to avoid printing the contents of the directory tmp.

55
Q

what are the characteristics of a hard link

A

– Programs cannot tell difference between ‘original’ and ‘target’
– Deleting a file just removes a link (unlink system call)
– Only when number of links is 0, the space is freed
– Limitations:
– same file system
– no directories (exceptions possible on some systems)
A file is deleted when no hard links to its inode exist. In the above example, if we remove
˜/csci2132/lab1/HelloWorld.java, we can still use ˜/csci2132/HelloWorld.java to access
the file.
To check the hard link count of a given file, use the ls -l command

56
Q

restrictions of hard links

A

There are some restrictions about creating hard links. First, hard links cannot span different disk drives. Second,
directories cannot have hard links, as this would generally make directory structure not a tree any more, and this
could possibly create an infinite recursion for the programs that traverse a directory structure. Additionally, it
would be ambiguous which would be a parent directory (..) of a hard-linked directory. Other than these, there are
no really design issues of why hard links on directories would not be allowed, so some systems may allow them in
exceptional situations (e.g., some newer Mac OS systems in the Time Machine application).

57
Q

how to create a hard link

A

The following command can be used to create a hard link:

ln target linkname

58
Q

what is a softlink

A

A soft link is a file that has the absolute or relative pathname of another file as its data part. When we create a soft
link, we create a new inode. This is equivalent to a file ‘shortcut’ in Windows. Strictly speaking, a soft link is not
a link to a file, it is a link to a pathname. The pathname in a soft link could not exist any more, and the link will
still be there, which could give us a wrong impression that the actual file exists, while it does not.

59
Q

how to create a softlink

A

ln -s target linkname

60
Q

why use hardlinks?

A

Some advantages of hard links are:
They are more efficient to use: faster to access and they do not require additional inodes. We do not need to worry
about which file is the ‘master’ file in order not to delete it by mistake. Hard links are particularly useful in some
situations, such as keeping incremental backups of a file directory structure. Some programs do not treat symbolic
links as ‘real’ files, which may or may not be desirable. For example, in a recursive copy, the cp command will
copy symbolic links to regular files as symbolic links.

61
Q

what are some examples of pipelines

A

As a couple more examples, the following line makes a list of files, sorts it, and prints the bottom part of the list:
ls | sort | tail
or, the following line will create the same list, and print the third last line:
ls | sort | tail -n 3 | head -n 1

62
Q

what is a regular expression

A

Regular expressions are used to address the problem of supporting fast and flexible text search: regular expression
search can be done using a DFA (you will learn this in a 3rd year course) which is fast, and they can be used to
specify a range of patterns and are thus flexible.
A regular expression is a sequence of normal and special characters specifying a pattern to match against strings.
It is used in many programs such as grep, sed, and perl. Again, we need learn metacharacters that can be used
to specify matching rules. Pay attention to the difference between these characters and wildcards in filename
substitution.

63
Q

what are some basic regular expressions (BRE)

A

– .: Matches any single character. For example, some strings that match a.b are: acb, a b, a-b, …
– []: Matches any of the single characters enclosed in brackets. We can use - to specify a range, and ˆ to
compliment the set (e.g. [ˆ ]). Other special characters, including ., *, ˆ (note that ˆ has other special
meanings outside []), $ and \ lose their special meanings inside [].
: 0 or more occurrences of the character that precedes it. For example, a can be used to specify the
following set of strings: empty string, a, aa, aaa, aaaa, …
– ˆ: Matches the beginning of a line.
– $: Matches the end of a line. ˆ and $ are useful if we want a pattern to occur as the prefix/suffix of a line.
– : Inhibits the meaning of any metacharacters.

64
Q

what is a filter

A

A filter is a program that gets most of its data from stdin and writes its main results to stdout. As pipes use one
program’s stdout as another’s stdin, it is natural that filters are often used as elements of pipelines.

65
Q

what is grep?

A

– grep reads a file or stdin and outputs lines matching a regular expression
– grep syntax
grep [options] BRE [file(s)]

If we enter the following command
grep ’$[0-9][0-9].[0-9][0-9]’ price
The following command will find all the dictionary words that start with a or b and end with b:
grep ’ˆ[ab].
b$’ /usr/share/dict/linux.words

66
Q

why use wildcards when we have grep?

A

There are a few reasons. First, for the example of listing java files, one ls command is enough
with wildcards, and we need not use pipes, so this is simpler. Second, wildcards can also be used with many other
commands such as cp to perform operations on a set of files, while regular expressions can only work with some
commands such as grep.

67
Q

What are some grep options?

A

– -n: Output lines preceded by line numbers
– -i: Ignores case
– -v: Output lines that don’t match
– -w: Restricts matching to whole words only

68
Q

what are some grep variations?

A

– grep : the standard grep
– grep -F (or fgrep) : searching for fixed strings
– grep -E (or egrep) : support for extended regular expressions

69
Q

What are extended regular expressions? (ERE)

A

– Include matacharacters: ? + | ( ) {
– These metacharacters can be used in BRE with a backslash; e.g., \?
– Back-referencing; e.g., (…)\1
– Further extension: PCRE — Perl-Compatible Regular Expressions
The extended regular expressions include the use of parentheses, and also the so-called back-referencing expressions
‘\n’, such as \1, \2, \3, and so on, which match substrings captured with parentheses. As an example,
the extended regular expression: ([ab])cd\1 would match strings: acda and bcdb, since in the first case ‘a’
is captured in the first set of parentheses, and ‘b’ is captured in the second case. As another example, we can use
these kinds of expressions to find words that have the first letter the same as the last one, and the second letter the
same as the second last letter. If we use a dictionary file, in which each word is placed in one line, we could use
the following regular expression: ˆ(.)(.).\2\1$
The back-referencing (backslash-n or \n) expressions, like \1 and \2 can be used several times in the same
expression; for example, the expression:
ˆ(.)(.).
\2\2\1\1$
would match the word ‘abcdebbaa’.

70
Q

how to move to the beginning of a line in emacs

A

(i) Control-a: Moving to the beginning of a line;

(ii) Control-e: Moving to the end of a line.

71
Q

how to copy and paste in emacs

A

(b) Press Control-@ to mark the first character of the block of text that you wish to copy. Emacs will probably
display the following message at the bottom of the screen “Mark set”. Once a mark is set, all text from that
position to the current position of the cursor is known as the current region in emacs. A note: Control-@
key combination is usually denoted as C-@ in Emacs.
(c) Move your cursor to the end of the third line.
(d) Press ESC w (Esc and then w) to copy the above block of text, i.e., the region, into the working memory. On
a Unix keyboard this combination can be obtained with Meta-w, or you should be able to obtain it on a PC
keyboard with Alt-w. In Emacs documents it is usually referred to as M-w.
(e) Move your cursor to the line below the last line of your program.
(f) C-y to paste the above block of text.

72
Q

undo in emacs

A

emacs hot key for undo is C-x u

73
Q

what are the advantages of separating the shell from the kernal

A

There are advantages of separating the shell from the
kernel. First, if something goes wrong in the shell, it will not bring down the system. Other programs can still be
running. Second, shells can be replaced without rewriting the kernel. Thus, it is easy to add new functionality by
writing a new shell. This is good software development practice.

74
Q

shell functionality

A
– Built-in commands
– Scripts
– Variables (local and environment)
– Redirection
– Wildcards
– Pipes
– Sequences (conditional and unconditional)
– Subshells
– Background processing
– Command substitution
75
Q

popular shells

A

– Bourne shell (/bin/sh): This shell replaced the original Thompson shell (which was the first UNIX shell).
– Korn shell (/bin/ksh)
– C shell (/bin/csh)
– TC shell (/bin/tcsh)
– Bash shell (/bin/bash)
– Note: Use cat /etc/shells to see shells available

76
Q

describe the bash shell

A

The Bash shell, or the Bourne Again shell, provides backward compatibility with the Bourne shell. It also
includes most useful features of C/Korn shells. It is licensed under GPL, and is thus open-source. Most Unix
systems have it.

77
Q

what is an internal shell command

A

The built-in commands are commands that a shell recognizes and executes
internally. They are called built-in commands or internal commands. The code for these commands is executed
within the shell program. This program is already in memory when shell is running so it is fast to execute them.
However, it is difficult to replace these commands with new versions as they are part of the shell. Therefore, these
commands typically execute simple tasks that we use frequently, or tasks which cannot be easily executed from a
another process, or ‘child’ process in this case. Some examples of internal commands are cd, logout, and echo,
although echo can also be an external command

78
Q

what is an external shell command

A

External commands are executable programs that are stored in the directory hierarchy, separate from the shell.
Some examples are: ls, grep, sort, cut, and uniq. (uniq and cut are covered in a lab.)

79
Q

what are the common shell variables

A

– The following are usually common variables among different shells:
– SHELL is the full pathname of the login shell
– HOME is the full pathname of the home directory
– PATH is the list of directories searched for a command
– USER is the username
– MAIL is the full pathname to the mailbox
– TERM is the type of the terminal

80
Q

what is a program

A

A program is a piece of code which is inactive and stored in a file

81
Q

what is a process

A

e a process is a running program which is

active. A process is instantiated from a program

82
Q

describe the components of process memory

A

– Code, which stores the program
– Data, which stores static data, i.e., data whose values are maintained throughout the execution
– Heap, which is used for dynamic allocation
– Stack, which is used to store temporary data

83
Q

what is a thread of execution

A

The active part of the process is the thread of execution. We know that the code section contains the program
(instructions). The process runs by executing the program instructions sequentially. The sequential execution of
program instructions forms a thread of execution.

84
Q

what information does a process control block contain (PCB)

A

– PCB information includes:
– Process Identification: PID (process identifier, unique nonnegative integer)
– The present position in the thread of execution
– Resources allocated to the process (e.g., memory, open files)
– Process ownership (user and group)
– Process state (running, sleeping, pre-empted, created, zombie)

85
Q

decribe the fork call and process creation

A

Processes can only be created by other processes. When a user runs a program, the shell (a process) creates the
process of the program.
We now describe how a parent process creates a child process. A parent process first ‘forks’ itself into two
processes, itself and a child process. The ‘fork’ operation is a system call. Remember that system calls provide an
interface for programmers to use kernel functionality. At this point, a new process has been created. However, the
new process is a copy (clone) of the old process. In particular, it executes the same code from the same position,
but it has its own thread. The new thread (child) is distinguished from the old thread (parent) by the return code
of the fork call. Since we usually want the child process to run a different program, the child process calls another
system call ‘exec’, to run a new program that replaces the child’s original program (which was the same as its
parent’s program). After this, the new program begins executing with the child control block.

86
Q

what is job control

A
– Shell facility for:
– Starting processes in the background
– Changing processes between background and foreground mode
– Suspending and resuming processes
– Terminating processes
– Displaying a list of current processes
– Foreground and background processes
87
Q

what is a foreground process

A

A foreground process is the process that controls the keyboard of a terminal

88
Q

what is a background process

A

A background process cannot read
from the terminal, but can output to the screen. To create a background process, we enter a command line with a
metacharacter & (ampersand) at the end. If we know that the background process might print a lot of output and
error messages, then it might be preferable to redirect stdout and stderr.

89
Q

what are some job and process control options

A

– Print jobs: jobs
– Print processes: ps
– Running job in background: bg or bg %jobID
– Bringing job to foreground: fg or fg %jobID
– Terminating a job or process: kill, kill %jobID, or kill PID

90
Q

give a brief history of the C language

A

– C is originally invented as a language for writing an operating system and other system software by Denis
Ritchie
– C optimizes for machine efficiency at the expense of increased implementation and debugging time
– A central difficulty in C programming: programmers must do their own memory management
– C assumes that you know what you are doing

91
Q

what lines of code should always be included in a basic C program

A
#include  — includes information about C’s standard I/O library.
int main() { — is a start of the “main” function.
printf — is a function from the standard I/O library to produce formatted output.
return 0; — return 0 as a return code from the function, which will be the exit code of the program.
92
Q

what are the three steps of compiling and what do they do

A

– Three steps:
– Preprocessing (by a preprocessor): modifies the program by following preprocessor directives
– Compiling (by a compiler): translates modified code into object code (machine instructions)
– Linking (by a linker): combines object code and additional code and produces an executable program
– gcc automatically executes these three steps

93
Q

what are directives

A
– Commands intended for the preprocessor
– Always begin line with #
– One line long
– No semicolon at the end
– Example: #include  — the content of stdio.h to be included into the program before
compiling
– stdio.h: an (actual) header file:
– /usr/include/stdio.h
94
Q

what are functions

A

– Building blocks from which C programs are constructed
– A function is a group of statements given a name
– Library functions: functions provided as a part of the C implementation; e.g., printf
– Main function: the function that is called automatically when the program is executed
– int main() or int main(void) means that main returns an integer value, and does not take any
parameters
– Nested functions not allowed by standard, but gcc allows them

95
Q

what is a statment

A
– A command to be executed when the program runs
– Must end with a semicolon
– Examples:
printf("hello, world\n");
return 0;
96
Q

how to use emacs to compile

A

(a) Open hello.c using emacs.
(b) Enter ‘M-x compile’ in emacs. This can be done by pressing ‘Esc x compile’ or ‘Alt-x compile’. If we
change our mind, we can press C-g (i.e., Ctrl-g) to abort the function. Going back to ‘verb M-x compile,’,
we then press Enter.
(c) You will be asked to enter the compile command. Use backspace key to delete the default command entirely,
and then enter the gcc -o hello hello.c command given earlier.
(d) This will split the current emacs window into two, and the bottom window will show the message generated
by the compiler.
(e) To go back to the single window mode so that we can see more lines of source code, enter C-x 1 (Control-x,
then 1 (digit one)).
(f) You can invoke any shell command without exiting emacs, and this includes running the compiled code.
To do this, enter M-! (e.g., Esc key followed by the ! key). Then you can enter any shell command. You
can now enter ./hello and you will see the result in emacs.
(g) Another way to run a program immediately after compilation is to enter M-x compile as before, followed
by Enter, and then enter the line:
gcc -o hello hello.c && ./hello
So, we are entering two commands: compilation, and run the program after. We will see later what is the
meaning of &&. A brief explanation for now is that after running the first command (gcc), the second
command is run (./hello) only if the first one was successful.

97
Q

how to send an email with a file attached in UNIX

A

pine mydalemail@dal.ca -attach hello.c

98
Q

defining names for preprocessor….why and how

A

– Macro definition (preprocessor directive):
#define PI 3.14159f
– or simply
#define PI 3.14159
– Preprocessor will replace each occurrence of token PI with the number
– A macro definition:
– does not define a variable
– is oblivious about the content of the replacement
– Macro replacement can be any sequence of tokens

99
Q

what are some modifiers (for printf)

A

– % character starts the specification, and it is mandatory.
– flags are optional characters, and there could be zero or more flags, such as + in %+d, specifying a mandatory
sign when printing a number, or - specifying left justification.
– minimal width is an optional positive integer specifying minimal width of the printout, as in %10d, which
may be useful in aligning numbers in a table.
– .precision is an optional period (.) followed by an integer (negative integer has the same effect as zero),
which is the number of decimal places to be printed for floating point numbers, but also minimal number of
digits for integers, and maximal number of characters for strings.
– length modifier is an optional character or two, such as l used for integers to denote a long integer, or it
can be used with ‘f’ as ‘lf’ to denote double instead of float. However, this particular modification is not
necessary.
– conversion specifier is the final mandatory character, denoting how the value of the variable is to be converted
to the printed string representation. The most frequently used ones are:
d for an integer,
f for a double or a float,
c for a character,
s for a string, and
% for a literal percent sign.