Exam Cards Flashcards

1
Q

/bin

A

/bin is a standard subdirectory of the root directory in Unix-like operating systems that contains the executable (i.e., ready to run) programs that must be available in order to attain minimal functionality for the purposes of booting (i.e., starting) and repairing a system. In addition to /bin, some of the other standard subdirectories in the root directory include /boot, /dev, /etc, /home, /mnt, /usr, /proc and /var. Among the contents of /bin are the shells (e.g., bash and csh), ls, grep, tar, kill, echo, ps, cp, mv, rm, cat, gzip, ping, su and the vi text editor. These programs can be used by both the root user (i.e., the administrative user) and ordinary users. /bin is by default in PATH, which is the list of directories that the system searches for the corresponding program when a command is issued. This means that any executable file (i.e., runnable program) in /bin can be run just by entering the file name at the command line and then pressing the ENTER key. The contents of PATH can be seen by using the echo command as follows: echo $PATH

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

root

A

The root directory, which is designated by a forward slash ( / ), is the top-level directory in the hierarchy of directories (also referred to as the directory tree) on Unix-like operating systems. That is, it is the directory that contains all other directories and their subdirectories as well as all files on the system.

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

What is a file?

A

A file is a named collection of related information that appears to the user as a single, contiguous block of data and that is retained in storage (e.g., a hard disk drive or a floppy disk).

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

What is a directory in Unix?

A

A directory in a Unix-like operating system is merely a special type of file that contains a list of the names of objects (i.e., files, links and directories) that appear to the user to be in it along with the corresponding inodes for each object.

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

Inode

A

An inode is a data structure on a filesystem that stores all the information about a filesystem object except its name and its actual data. A data structure is a way of storing data so that it can be used efficiently.

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

Filesystem

A

A filesystem is the hierarchy of directories that is used to organize files on a computer system.

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

/sbin

A

contains additional programs to /bin that are used to boot the system as well as administrative and system maintenance programs that are only available to the root user.

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

/usr/bin

A

contains executable programs that are not required for booting or repairing the system.

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

/etc

A

Supervisor directory commands, configuration files, disk configuration files, valid user lists, groups, ethernet, hosts, where to send critical messages. This is the nerve center of your system, it contains all system related configuration files in here or in its sub-directories. A “configuration file” is defined as a local file used to control the operation of a program; it must be static and cannot be an executable binary. Examples: /etc/hosts.[allow, deny]: you can control access to your network by using these files. Adds hosts that you want to grant access to your network to the hosts.allow file; add hosts that you want to deny access to hosts.deny. /etc/ftpusers: this file contains the login names of users who are not allowed to log in by way of FTP. For security reasons, it is recommended to add the root user to this file. /etc/inittab: this file describes what takes place or which processes are started at bootup or at different runlevels. A runlevel is defined as the state in which the Linux box currently is in. Linux has seven runlevels, from 0-6. /etc/passwd: this file contains user information. Whenever a new user is added, an entry is added to this file containing the user’s login name, password and so on. This file is readable by everyone on the system. If the password field contains “x”, then encrypted passwords are stored in /etc/shadow, a file that is accessible only by the root user. /etc/profile: when a user logs in, a number of configuration files are executed, including /etc/profile. This file contains settings and global startup information for the bash shell. /etc/shells: this file contains the names of all the shells installed on the system, along with their full path names.

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

/usr/include

A

This is where all of the system’s general-use include files for the C programming language should be placed. The directory for ‘header files’, needed for compiling user space source code.

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

/usr/lib

A

The /usr/lib directory contains more libraries and data files used by various UNIX commands. UNIX program libraries

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

/var/log

A

Log files from the system and various programs/services, especially login (/var/log/wtmp, which logs all logins and logouts into the system) and syslog (/var/log/messages, where all kernel and system program message are usually stored). Files in /var/log can often grow indefinitely, and may require cleaning at regular intervals. Something that is now normally managed via log rotation utilities such as ‘logrotate’. This utility also allows for the automatic rotation compression, removal and mailing of log files. Logrotate can be set to handle a log file daily, weekly, monthly or when the log file gets to a certain size. Normally, logrotate runs as a daily cron job. This is a good place to start troubleshooting general technical problems

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

/var

A

Variable sized files - can grow and shrink dynamically, such a users mail spool and print spool files.

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

/

A

the root directory

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

.

A

current directory

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

..

A

parent directory

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

~

A

home directory (tilde)

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

ls

A

The ls command is used to list the contents of a directory. It is probably the most commonly used Linux command.

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

ls -l

A

List information about the FILEs (the current directory by default) in long format.

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

ls -la ..

A

List all files (even ones with names beginning with a period character, which are normally hidden) in the parent of the working directory in long format

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

$*

A

The variable $*, is similar to $@, but does not preserve any whitespace, and quoting, so “File with spaces” becomes “File” “with” “spaces”.

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

$?

A

this contains the exit value of the last run command Exit status is a numerical value returned by every command upon its completion. As a rule, most commands return an exit status of 0 if they were successful, and 1 if they were unsuccessful.

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

$#

A

$# is the number of parameters the script was called with.

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

$$

A

The $$ variable is the PID (Process IDentifier) of the currently running shell. This can be useful for creating temporary files, such as /tmp/my-script.$$ which is useful if many instances of the script could be run at the same time, and they all need their own temporary files.

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

$!

A

The $! variable is the PID of the last run background process. This is useful to keep track of the process as it gets on with its job.

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

$0

A

the file name of the current script

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

$n

A

These variables correspond to the arguments with which a script was invoked. Here n is a positive decimal number corresponding to the position of an argument (the first argument is $1, the second argument is $2, and so on).

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

How to assign the output of a command to a variable in bash?

A

You need to use command substitution feature of bash. It allows you to run a shell command and store its output to a variable. To assign output of any shell command to variable in bash, use the following command substitution syntax: var=$(command-name-here) var=$(command-name-here arg1) var=$(/path/to/command) var=$(/path/to/command arg1 arg2) OR var=command-name-here var=command-name-here arg1 var=/path/to/command var=/path/to/command arg1 arg2

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

var=10; echo $var + 5

A

result: 10+5

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

What is a header file?

A

A header file is a file with extension .h which contains C function declarations and macro definitions and to be shared between several source files. There are two types of header files: the files that the programmer writes and the files that come with your compiler. Both user and system header files are included using the preprocessing directive #include. It has following two forms: #include #include “file”

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

List some common headers in the standard C library.

A
  • defines common mathematical functions - defines a boolean data type - defines core input and output functions - Defines numeric conversion functions, pseudo-random numbers generation functions, memory allocation, process control functions - defines string handling functions See: http://en.cppreference.com/w/c/header
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

How does the C preprocessor work?

A

The C preprocessor, often known as cpp, is a macro processor that is used automatically by the C compiler to transform your program before compilation. It is called a macro processor because it allows you to define macros, which are brief abbreviations for longer constructs. The C preprocessor is intended to be used only with C, C++, and Objective-C source code. In the past, it has been abused as a general text processor.

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

include

A

include tells the C compiler to find the standard header called and add it to this program. In C, you often have to pull in extra optional components when you need them. contains descriptions of standard input/output functions which you can use to send messages to a user, or to read input from a user.

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

printf

A

printf is the formatted printing function that is declared in the file stdio.h - which is why you had to #include that at the start of the program.

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

The header shall define the following symbolic constants, each of which expands to a distinct constant expression of the type: void (*)(int) whose value matches no declarable function.

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

stdlib.h is a standard C header that declares among other things the malloc(), calloc(), free() functions.

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

malloc.h

A

malloc.h is a non-standard header, found on many systems where it often defines additional functions specific to the malloc implementation used by that platform.

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

libraries vs header files

A

Header files declares things, like structs and function prototypes. Libraries contains the implementation, the compiled code. You link to librarie, and you #include header files.

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

scanf()

A

The scanf() function is the input method equivalent to the printf() output function - simple yet powerful. In its simplest invocation, the scanf format string holds a single placeholder representing the type of value that will be entered by the user.

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

storage classes in C:

A

A storage class defines the scope (visibility) and life time of variables and/or functions within a C Program. 1. auto 2. register 3. static 4. extern

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

auto storage class

A

auto is the default storage class for all local variables. auto can only be used within functions, i.e. local variables.

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

register storage class

A

register is used to define local variables that should be stored in a register instead of RAM. This means that the variable has a maximum size equal to the register size (usually one word) and cant have the unary ‘&’ operator applied to it (as it does not have a memory location). Register should only be used for variables that require quick access - such as counters. It should also be noted that defining ‘register’ goes not mean that the variable will be stored in a register. It means that it MIGHT be stored in a register - depending on hardware and implimentation restrictions.

Variables which are used repeatedly or whose access times are critical may be declared to be of storage class register.

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

static storage classes

A

static is the default storage class for global variables. static can also be defined within a function. If this is done the variable is initalised at run time but is not reinitalized when the function is called. This inside a function static variable retains its value during vairous calls.

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

extern storage class

A

extern is used to give a reference of a global variable that is visible to ALL the program files. When you use ‘extern’ the variable cannot be initalized as all it does is point the variable name at a storage location that has been previously defined.

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

pwd.h

A

The header provides a definition for struct passwd, which includes the following members: char *pw_name user’s login name uid_t pw_uid numerical user ID gid_t pw_gid numerical group ID char *pw_dir initial working di rectory char *pw_shell program to use as shell The gid_t and uid_t types are defined as described in .

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

C preprocessor

A

The C preprocessor is a macro processor that is used automatically by the C compiler to transform your program before actual compilation. It is called a macro processor because it allows you to define macros, which are brief abbreviations for longer constructs. The C preprocessor provides four separate facilities that you can use as you see fit: - Inclusion of header files. These are files of declarations that can be substituted into your program. - Macro expansion. You can define macros, which are abbreviations for arbitrary fragments of C code, and then the C preprocessor will replace the macros with their definitions throughout the program. - Conditional compilation. Using special preprocessing directives, you can include or exclude parts of the program according to various conditions. - Line control. If you use a program to combine or rearrange source files into an intermediate file which is then compiled, you can use line control to inform the compiler of where each source line originally came from.

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

CPP 1. Transformations made globally

A
  1. All C comments are replaced with single spaces. 2. Backslash-Newline sequences are deleted, no matter where. This feature allows you to break long lines for cosmetic purposes without changing their meaning. 3. Predefined macro names are replaced with their expansions
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
48
Q

CPP2. Preprocessing directives

A

Preprocessing directives are lines in your program that start with #'. The #’ is followed by an identifier that is the directive name. For example, #define' is the directive that defines a macro. Whitespace is also allowed before and after the #’.

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

CPP3. Header files

A

A header file is a file containing C declarations and macro definitions (see section 1.4 Macros) to be shared between several source files. You request the use of a header file in your program with the C preprocessing directive #include'. - System header files declare the interfaces to parts of the operating system. You include them in your program to supply the definitions and declarations you need to invoke system calls and libraries. - Your own header files contain declarations for interfaces between the source files of your program. Each time you have a group of related declarations and macro definitions all or most of which are needed in several different source files, it is a good idea to create a header file for them. Including a header file produces the same results in C compilation as copying the header file into each source file that needs it. But such copying would be time-consuming and error-prone. With a header file, the related declarations appear in only one place. Both user and system header files are included using the preprocessing directive #include’. It has three variants: 1. #include - This variant is used for system header files. It searches for a file named file in a list of directories specified by you, then in a standard list of system directories. You specify directories to search for header files with the command option -I' 2. #include "file" - This variant is used for header files of your own program. It searches for a file named file first in the current directory, then in the same directories used for system header files. The current directory is the directory of the current input file. It is tried first because it is presumed to be the location of the files that the current input file refers to. (If the -I-‘ option is used, the special treatment of the current directory is inhibited.) 3. #include anything else - This variant is called a computed #include. Any `#include’ directive whose argument does not fit the above two forms is a computed include. The text anything else is checked for macro calls, which are expanded (see section 1.4 Macros). When this is done, the result must fit one of the above two variants–in particular, the expanded text must in the end be surrounded by either quotes or angle braces.

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

CCP4. Macros

A

A macro is a sort of abbreviation which you can define once and then use later. A simple macro is a kind of abbreviation. It is a name which stands for a fragment of code. Some people refer to these as manifest constants. Before you can use a macro, you must define it explicitly with the #define' directive. #define’ is followed by the name of the macro and then the code it should be an abbreviation for. For example, #define BUFFER_SIZE 1020 defines a macro named BUFFER_SIZE' as an abbreviation for the text 1020’. You can also have macros that accept arguments - A macro that accepts arguments is called a function-like macro because the syntax for using it looks like a function call. Also, several simple macros are predefined. You can use them without giving definitions for them. They fall into two classes: standard macros and system-specific macros. Examples: __OPTIMIZE__ GNU CC defines this macro in optimizing compilations. It causes certain GNU header files to define alternative macro definitions for some system library functions. The C preprocessor normally has several predefined macros that vary between machines because their purpose is to indicate what type of system and machine is in use. example: unix

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

CPP5. Conditionals

A

In a macro processor, a conditional is a directive that allows a part of the program to be ignored during compilation, on some conditions. In the C preprocessor, a conditional can test either an arithmetic expression or whether a name is defined as a macro. A conditional in the C preprocessor resembles in some ways an if' statement in C, but it is important to understand the difference between them. The condition in an if’ statement is tested during the execution of your program. Its purpose is to allow your program to behave differently from run to run, depending on the data it is operating on. The condition in a preprocessing conditional directive is tested when your program is compiled. Its purpose is to allow different code to be included in the program depending on the situation at the time of compilation. #if X == 1 … #elif X == 2 … #else /* X != 2 and X != 1*/ … #endif /* X != 2 and X != 1*/ Example:

The directives concerned are: #if, #ifdef, #ifndef, #elif,#else, #endif together with the preprocessor unary operator defined.

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

CPP6. Combining source files

A

One of the jobs of the C preprocessor is to inform the C compiler of where each line of C code came from: which source file and which line number.

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

CPP7. Invoking the C Preprocessor

A

Most often when you use the C preprocessor you will not have to invoke it explicitly: the C compiler will do so automatically. However, the preprocessor is sometimes useful on its own. The C preprocessor expects two file names as arguments, infile and outfile. The preprocessor reads infile together with any other files it specifies with #include'. All the output generated by the combined input files is written in outfile. Either infile or outfile may be -‘, which as infile means to read from standard input and as outfile means to write to standard output. Also, if outfile or both file names are omitted, the standard output and standard input are used for the omitted file names. Some examples of commands options accepted by CPP: -C' Do not discard comments: pass them through to the output file. Comments appearing in arguments of a macro call will be copied to the output before the expansion of the macro call. -Wall’ Requests both -Wtrigraphs' and -Wcomment’ (but not -Wtraditional' or -Wundef’). -I directory' Add the directory directory to the head of the list of directories to be searched for header files (see section 1.3.2 The #include’ Directive). This can be used to override a system header file, substituting your own version, since these directories are searched before the system header file directories. If you use more than one -I' option, the directories are scanned in left-to-right order; the standard system directories come after. -nostdinc’ Do not search the standard system directories for header files. Only the directories you have specified with -I' options (and the current directory, if appropriate) are searched. -gcc’ Define the macros __GNUC__ and __GNUC_MINOR__. These are defined automatically when you use gcc -E'; you can turn them off in that case with -no-gcc’.

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

What’s the freaking purpose of the C preprocessor?

A

it can equally well be though of as a separate program which transforms C source code containing preprocessor directives into source code with the directives removed.

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

Summarize the importance of the C preprocessor.

A

There are only a very few aspects that are really important.

The ability to define macros and function macros is very important, being widely used in almost every C program except the most trivial.

The conditional compilation has two important uses; one is the ability to compile with or without debugging statements included in a program, the other is to be able to select machine or application dependent statements.

Obviously, file inclusion is fundamentally important.

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

What is pipelining?

A

You can connect two commands together so that the output from one program becomes the input of the next program. Two or more commands connected in this way form a pipe.

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

What is the ‘grep’ command?

A

The grep program searches a file or files for lines that have a certain pattern. The syntax is:

$grep pattern file(s)

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

What does the sort command do?

A

The sort command arranges lines of text alphabetically or numerically.

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

What does the more command do?

A

A long output would normally zip by you on the screen, but if you run text through more or pg as a filter, the display stops after each screenful of text.

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

What is the GNU build system for?

A

1) Building, Porting, and Packaging Source Code.

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

What does the ps command do?

A

report a snapshot of the current processes.

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

What command from GNU build does the building?

A

make, or make all

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

What tools in GNU Build are for porting and packaging?

A

(autotools)

1) autoconf
2) automake
3) libtool

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

Name three advnaced packaging tools on Debian?

A
  1. dh_make: Debian Packaging
  2. dpkg: install/de-install
  3. aptitude/synatpic: dealswith software repositories
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
66
Q

Explain this:

tar -zxvf test123.tar.gz

A

The tar extension is short for ‘tape archive. Tar files are used “To combine multiple files and/or directories into a single file”. The .gz extension tells us that the file is compressed and needs to be unzipped.

where

z– unzip

x– extract the file

v– verbose

f– forcefully done

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

If we have no Makefile to build our source files into a program what command do we need to run?

A

You need to run ./configure. This creates a Makefile based on the general state of your OS.

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

What does the ‘kill’ command do?

A

Use the kill command to send a signal to each process specified by a pid (process identifier). The default signal is SIGTERM (terminate the process).

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

The ./configure command turns

1) configure.ac into what?
2) and form what file does it create the Makefile?

A

1) Configure and aclocal.m4
2) Makefile.in (in for incomplete)

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

What does the top command do?

A

The top program provides a dynamic real-time view of a running system. It can display system summary information as well as a list of tasks currently being managed by the Linux kernel.

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

During the ./configure command configure.h.in

is turned into what/

A

Configure.h

The.in is removed becuase it is no longer incomplete

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

vmstat

A

vmstat reports information about processes, memory, paging, block IO, traps, and cpu activity.

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

What file does autoscan produce?

A

Autoscan produces configure.scan which must be renamed to configure.ac

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

free command

A

free is a command which can give us valuable information on available RAM in Linux machine.

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

What does configure.ac contain?

A

It contains special macros:

AC_Marcros for autoconf

AM_Mcros for automake

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

What is the difference between downloading from source and downloading from binaries?

A

Installing from source means you compile the souce code and then install.

Installing from binary means someone allready compiled it into binary and you just have to put it on your computer.

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

What is better? Installing from binary or from source? And why?

A

Fromsourceis better:

  1. ) It can be optimized for (for example) an Athlon processor whereas with binaries you’re stuck with it being compiled for whatever system the person who compiled it was running.
  2. ) Also, if you run a binary and it needs shared libraries, such as GTK, then you have to have the EXACT same version of the libraries on your system as those on the system the binary was compiled on.

In general, from source allows for more custom installation.

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

What is the target and what is the pre-requisite here?

all: prog 1 prog 2

A

The syntax requires that targets are onthe left and the targets dependencies are to it’s right.

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

What is a pointer?

A

A pointer is a value that designates the address (i.e., the location in memory), of some value.

Pointers are variables that hold a memory location – the location of some other variable. One can access the value of the variable pointed to using the dereferencing operator ‘*’. Pointers can hold any data type, even functions

Pointers are variables that don’t hold the actual data. Instead they point to the memory location of some other variable. For example,

int *pointer = &variable;

defines a pointer to an int, and also makes it point to the particular integer contained in variable.

The ‘*’ is what makes this an integer pointer. To make the pointer point to a different integer, use the form

pointer = &sandwiches;

Where & is the address of operator.

Often programmers set the value of the pointer to NULL (a standard macro defined as 0 or (void*)0 ) like this:

pointer = NULL;

This tells us that the pointer isn’t currently pointing to any real location. Additionally, to dereference (access the thing being pointed at) the pointer, use the form:

value = *pointer;

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

List some standard targets for a Makefile

A
  • all
  • clean
  • uninstall
  • install
  • dist
  • dist clean
    *
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
81
Q

A makefile is processed in two stages by the make command? Whatarethese stages?

A
  1. Compute a graph of dependencies
  2. Rebuild necessary targets
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
82
Q

In a makefile what does $@ refer too?

prog1: prog1.0 circle.o

   $(cc) $(LDFLAGS) %^  -o $@
A

The name of the target of a rule.

So $@ is short for prog1 in this case.

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

Struct

A

A data structure (“struct”) contains multiple pieces of data. Each piece of data (called a “member”) can be accessed by the name of the variable, followed by a ‘.’, then the name of the member. (Another way to access a member is using the member operator ‘->’).

The member variables of a struct can be of any data type and can even be an array or a pointer. One defines a data structure using the struct keyword. For example,

struct mystruct

{

   int int\_member;

   double double\_member;

   char string\_member[25];

} variable;

variable is an instance of mystruct. You can omit it from the end of the struct declaration and declare it later using:

struct mystruct variable;

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

What does malloc do?

A

The malloc function returns a pointer to dynamically allocated memory (or NULL if unsuccessful). The size of this memory will be appropriately sized to contain the MyStruct structure.

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

What does $< refer too?

prog1: prog1.o circle.o

   $(cc) $(LDFLAGS) $\<  -o $@
A

The name of the first prerequisite of a rule.

In this case, $< is short for prog1.o

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

What does $^ refer too?

prog1: prog1.o circle.o

   $(cc) $(LDFLAGS) $^  -o $@
A

The names of all prerequisites of a rule.

In this case, $^ refers to prog1.o and circle.o

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

What does the ar command do here:

ar -cr libname.a obj1.o obj2.o

A

ar -archiver, creates static libraries by grouping object files.

  • c stands for create
  • r stands for insert
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
89
Q

Howdo we get the value of an object which a pointer p is pointing to?

A

*p

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

How do we get the address of an object which a pointer p is pointing to?

A

&p

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

If p and q are both pointer types is this legal?

p = q

A

Yes, becuase pointers are variables and can be assigned.

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

Without pointers what would be the problem with a function like this:

swap(a,b)

that simly swapped the values of a and b?

A

C is pass by value. unless you use pointers. Pointers allow you to change the address a variable points to (pass by reference) and this allows a function like swap(&a &b) to chnage the vlues outside it’s own scope.

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

Pointer deferencing

A

The pointer p points to the variable a.

To access a value to which a pointer points, the * operator is used. Another operator, the -> operator is used in conjunction with pointers to structures.

A short example is shown below.

int c, d;

int *pj;

struct MyStruct astruct;

struct MyStruct *bb;

c = 10;

pj = &c; /* pj points to c */

d = *pj; /* d is assigned the value to which pj points, 10 */

pj = &d; /* now points to d */

*pj = 12; /* d is now 12 */

bb = &astruct;

(*bb).m_aNumber = 3; /* assigns 3 to the m_aNumber member of astruct */

bb->num2 = 44.3; /* assigns 44.3 to the num2 member of astruct */

*pj = bb->m_aNumber; /* eqivalent to d = astruct.m_aNumber; */

When dereferencing a pointer that points to an invalid memory location, an error often occurs which results in the program terminating. The error is often reported as a segmentation error. A common cause of this is failure to initialize a pointer before trying to dereference it.

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

Here is an array called ‘a’

[h,e,l,l,o,]

Will this return something

‘a’?

A

Yes, if ‘a’ is an array then ‘a’ is the same as a[0] so it will return ‘h’

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

Canyou write this in another format?

array[3]

A

*(array + 3)

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

Are these identical?

  1. char a[] = hello;

and

  1. char *a = hello
A

No, they are different although they will give the same output.

  1. This creates a spacein the stack for storing something thesame size as ‘hello’ and then puts the contents of ‘hello’ into that spaceon the stack.
  2. Creating a pointer means that a points to the word ‘hello’ somewhere in read-only memory.

With the first option ‘hello’ is in read-write memory. In the second, it is not.

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

What is a c-string?

A

A c-string can be contrasted with a string literal.

The later is stored in read only memory as a result of this type of declaration and cannot be altered

char * p = “const cstring”;

A c-string can be altered becuase it is declared with an array which copies values from read-only memory into the arraywhich is stroed onthe stack(read-write)

char cstr[] = “c-string”;

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

malloc

A

The C function malloc is the means of implementing dynamic memory allocation. It is defined in stdlib.h or malloc.h, depending on what operating system you may be using.

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

free() in C

A

The corresponding call to release allocated memory back to the operating system is free. When dynamically allocated memory is no longer needed, free should be called to release it back to the memory pool.

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

Can you change the address of pointers and variables?

A

No, you can change where a pointer points, but a variables address is stroed statically and cannot be changed like this:

&var = new address.

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

What’s the point of malloc?

A

Sometimes it is not known at the time the program is written how much memory will be needed for some data. In this case we would want to dynamically allocate required memory after the program has started executing. To do this we only need to declare a pointer, and invoke malloc when we wish to make space for the elements in our array, or, we can tell malloc to make space when we first initialize the array. Either way is acceptable and useful.

So how do we malloc an array of ten ints like before? If we wish to declare and make room in one hit, we can simply say

int *array = malloc(10*sizeof(int));

We only need to declare the pointer; malloc gives us some space to store the 10 ints, and returns the pointer to the first element, which is assigned to that pointer.

Important note! malloc does not initialize the array; this means that the array may contain random or unexpected values! Like creating arrays without dynamic allocation, the programmer must initialize the array with sensible values before using it. Make sure you do so, too.

It is not necessary to immediately call malloc after declaring a pointer for the allocated memory. Often a number of statements exist between the declaration and the call to malloc, as follows:

int *array = NULL;

printf(“Hello World!!!”);

/* more statements */

array = malloc(10*sizeof(int)); /* delayed allocation */

/* use the array */

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

Name two ways in which memory can be allcated to an array?

A
  1. ) Statically at complile time
  2. ) Dynamically at run time
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
104
Q

What arethe different ways we can initialize or fill up an array in C?

A
  1. ) We can loop with i++ and use the array as such a[i]
    2) We can use i++ again, but using *(a+1)
    3) We can write a[5] = {1,2,3} // 4,5 will equal zero
    4) We canwrite a[] = {1,2,3} // Now size is of 3
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
105
Q

Error-checking when using malloc

A

When we want to use malloc, we have to be mindful that the pool of memory available to the programmer is finite. As such, we can conceivably run out of memory! In this case, malloc will return NULL. In order to stop the program crashing from having no more memory to use, one should always check that malloc has not returned NULL before attempting to use the memory; we can do this by

int *pt = malloc(3 * sizeof(int));

if(pt == NULL)

{

fprintf(stderr, “Out of memory, exiting\n”);

exit(1);

}

Of course, suddenly quitting as in the above example is not always appropriate, and depends on the problem you are trying to solve and the architecture you are programming for. For example if program is a small, non critical application that’s running on a desktop quitting may be appropriate.

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

calloc in C

A

The calloc function allocates space for an array of items and initilizes the memory to zeros. The call mArray = calloc( count, sizeof(struct V)) allocates count objects, each of whose size is sufficient to contain an instance of the structure struct V. The space is initialized to all bits zero. The function returns either a pointer to the allocated memory or, if the allocation fails, NULL.

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

realloc() in C

A

include <stdio.h></stdio.h>

The C library function void *realloc(void *ptr, size_t size) attempts to resize the memory block pointed to by ptr that was previously allocated with a call to malloc or calloc.

ptr – This is the pointer to a memory block previously allocated with malloc, calloc or realloc to be reallocated.If this is NULL, a new block is allocated and a pointer to it is returned by the function.

size – This is the new size for the memory block, in bytes.If it is 0 and ptr points to an existing block of memory, the memory block pointed by ptr is deallocated and a NULL pointer is returned.

Example:

int main() {

char *str; /* Initial memory allocation */

str = (char *) malloc(15);

strcpy(str, “tutorialspoint”);

printf(“String = %s, Address = %u\n”, str, str);

/* Reallocating memory */

str = (char *) realloc(str, 25);

strcat(str, “.com”);

printf(“String = %s, Address = %u\n”, str, str); free(str); return(0);

}

Result:

String = tutorialspoint, Address = 355090448

String = tutorialspoint.com, Address = 355090448

108
Q

What is the differenc between:

1.) Int* pnt

and

2.) int *pnt

A

No difference.

109
Q

What are the three different types of memory allocation in C?

A
  1. ) Static
  2. ) Automatic
  3. ) Dynamic
110
Q

What is wrong twith th following:

extern int global4 = 5;

A

Extern variables shouldn’t be initialized becuase they are definedexternally in some other file.

111
Q

Name the main areas of memory in relation to C?

A
  1. ) Low Address: Text
  2. ) Initialized Variables
  3. ) Uninitialized Variables
    4) Heap (For dynamic allocation)
    5) Stack (Func args, Return values, automatic variables)
    6) High Address: Command Line Arguments & Enviornmental Variabes.
112
Q

free() in C

A

Memory that has been allocated using malloc, realloc, or calloc must be released back to the system memory pool once it is no longer needed. This is done to avoid perpetually allocating more and more memory, which could result in an eventual memory allocation failure. Memory that is not released with free is however released when the current program terminates on most operating systems. Calls to free are as in the following example.

int *myStuff = malloc( 20 * sizeof(int));

if (myStuff != NULL)

{

/* more statements here */

/* time to release myStuff */

free( myStuff );

}

113
Q

What is the defualt storage type forlocal variables?

Where are these variables stored in memory?

A

Local variables are stored as auto by defualt from the auto class.This means they are stored in the stack and they are only alive for a short time while they haven’t been popped from the stack. When auto variables are defined, memry is allocated, but not initialized.

114
Q

Is the register class for global or local variables?

A

The register class is used for local variables. It’s used for optomization, usually.

115
Q

What is the defualt storage class for globl variables?

A

Static. The static class can be used for both global and loval variables.

116
Q

Wht is the lifetime of a static variable?

A

The same as the lifetime of the program.

117
Q

What does the extern class allow?

A

It allows one to access global variables that are defined in other files.

118
Q

What are memory leaks?

A

Memory leaks are when Malloc()is used to as assign memory dynamically, but the memory is never deallocated or freed aftwards.

119
Q

OSI Model

A

(Open Systems Interconnection model) The International Standards Organization’s OSI model serves as a standard template for describing a network protocol stack

120
Q

Application Layer

A

This top layer defines the language and syntax that programs use to communicate with other programs. The application layer represents the purpose of communicating in the first place. For example, a program in a client workstation uses commands to request data from a program in the server. Common functions at this layer are opening, closing, reading and writing files, transferring files and e-mail messages, executing remote jobs and obtaining directory information about network resources.

This is what you see, such as your browser or e-mail client.

A range of protocols are available at this layer, many of them based on tcp/ip

FTP, TFT, DNS, HTTP(S), POP3, WAP, Telnet, SMTP

121
Q

Presentation layer of OSI model

A

When data are transmitted between different types of computer systems, the presentation layer negotiates and manages the way data are represented and encoded. For example, it provides a common denominator between ASCII and EBCDIC machines as well as between different floating point and binary formats. Sun’s XDR and OSI’s ASN.1 are two protocols used for this purpose. This layer is also used for encryption and decryption.

Data is encrytped/decrypted at this layer. Character encoding is used and the data is made presentable for the application layer.

JPEG, MPEG

122
Q

Session layer of OSI model

A

Provides coordination of the communications in an orderly manner. It determines one-way or two-way communications and manages the dialog between both parties; for example, making sure that the previous request has been fulfilled before the next one is sent. It also marks significant parts of the transmitted data with checkpoints to allow for fast recovery in the event of a connection failure.

In practice, this layer is often not used or services within this layer are sometimes incorporated into the transport layer.

Control & Tunnelling protocols are used at this layer

to start, stop, and restart connections between

two devices. It can operate at half duplex and full duplex

SQL

123
Q

OSI’s Transport Layer

A

This layer is responsible for overall end-to-end validity and integrity of the transmission. The lower layers may drop packets, but the transport layer performs a sequence check on the data and ensures that if a 12MB file is sent, the full 12MB is received.

“OSI transport services” include layers 1 through 4, collectively responsible for delivering a complete message or file from sending to receiving station without error.

TCP protocol uses segments

UDP protocols uses datagrams

TCP is a connectionless protocol

UDP is connectionless

UDP is thus faster, but offers no confirmation

that your data has been sent

Recognizes duplicates

124
Q

what are static libraries?

A

When linking is performed during the creation of an executable or another object file, it is known as static linking or early binding. In this case, the linking is usually done by alinker, but may also be done by the compiler. A static library, also known as an archive, is one intended to be statically linked. Originally, only static libraries existed. Static linking must be performed when any modules are recompiled.

They have a .a extension

125
Q
A
126
Q

What is a shared library?

A

A shared library or shared object is a file that is intended to be shared by executable files and further shared objects files. Modules used by a program are loaded from individual shared objects into memory at load time or run time, rather than being copied by a linker when it creates a single monolithic executable file for the program.

127
Q

OSI’s Network layer

A

The network layer establishes the route between the sender and receiver across switching points, which are typically routers. The most ubiquitous example of this layer is the IP protocol in TCP/IP (see TCP/IP). IPX, SNA and AppleTalk are other examples of routable protocols, which means that they include a network address and a station address in their addressing system. This layer is also the switching function of the dial-up telephone system. If all stations are contained within a single network segment, then the routing capability in this layer is not required.

128
Q

Where are headers stored?

A

In /usr/local/include or/urs/include

129
Q

Datalink Layer - Layer 2

A

The data link is responsible for node to node validity and integrity of the transmission. The transmitted bits are divided into frames; for example, an Ethernet, Token Ring or FDDI frame in local area networks (LANs). Frame relay and ATM are also at Layer 2. Layers 1 and 2 are required for every type of communications.

130
Q

What doe this do?

FILE s t r e am = f o p e n (“ t e s t . t x t “ , “r” ) ;

A

File* is a key data structure for input/output streams. It takes two args:

  1. ) The file to be streamed
    2) An argument to specifiy whatyou wnat to do with the file

‘r’ is for read

‘a’ is for append

‘w’ is create a text file for writing or make empty and writable.

131
Q

Layer 1 - Physical layer

A

The physical layer is responsible for passing bits onto and receiving them from the connecting medium. This layer has no understanding of the meaning of the bits, but deals with the electrical and mechanical characteristics of the signals and signaling methods. For example, it comprises the RTS and CTS signals in an RS-232 environment, as well as TDM and FDM techniques for multiplexing data on a line. SONET also provides layer 1 capability.

Cable, NIC, Hub, he bitstream is translated in voltages and transmitted though different media

132
Q

Sumarize the stages of the UNIX boot process

A
  1. BIOS: Basic input/output system executes MBR
  2. MBR: Master Boot Record executes GRUB
  3. Grand Unified Boot Loader executes Kernel
  4. Kernel executes /sbin.init
  5. init executes runlevle programs
  6. runlevel programs areexecuted from /etc/rc.d/rc*.d/
133
Q

Describe the Unix boot process.

A

A quick view of booting sequence:

Power on
CPU jumps to BIOS
BIOS runs POST
Finds first bootable device
Load and execute MBR
Load OS
User prompt

134
Q

Stage 1 Boot Process

A

This is the first stage of booting process. When you power on/Restart your machine the power is supplied to SMPS (switched-mode power supply) which converts AC to DC. The DC power is supplied to all the devices connected to that machine such as Motherboard HDD’s, CD/DVD-ROM, Mouse, keyboard etc. The most intelligent device in the computer is Processor(CPU), when supplied with power will start running its sequence operations stored in its memory. The first instruction it will run is to pass control to BIOS(Basic Input/Output System)to do POST(Power On Self Test). Once the control goes to BIOS it will take care of two things

Run POST operation.

Selecting first Boot device.

POST operation: POST is a processes of checking hardware availability. BIOS will have a list of all devices which are present in previous system boot. In order to check if a hardware is available for the present booting or not it will send an electric pulse to each and every device in the list that it already have. If an electrical pulse is returned from that device it will come to a conclusion the hardware is working fine and ready for use. If it does not receive a single from a particular device it will treat that device as faulty or it was removed from the system. If any new hardware is attached to the system it will do the same operation to find if its available or not. The new list will be stored in BIOS memory for next boot.

Selecting First Boot Device: Once the POST is completed BIOS will have the list of devices available. BIOS memory will have the next steps details like what is the first boot device it has to select etc. It will select the first boot device and gives back the control to Processor(CPU). Suppose if it does not find first boot device, it will check for next boot device, if not third and so on. If BIOS do not find any boot device it will alert user stating “No boot device found”.

135
Q

Stage 2 of the Unix Boot Process

A

Once the BIOS gives control back to CPU, it will try to load MBR of the first boot device(We will consider it as HDD). MBR is a small part of Hard Disk with just a size of 512 Bytes, I repeat its just 512 Bytes. This MBR resides at the starting of HDD or end of HDD depending on manufacturer.

What is MBR?

MBR(Master Boot recorder) is a location on disk which have details about

Primary boot loader code(This is of 446 Bytes)

Partition table information(64 Bytes)

Magic number(2 Bytes)

Which will be equal to 512B (446+64+2)B.

Primary Boot loader code: This code provides boot loader information and location details of actual boot loader code on the hard disk. This is helpful for CPU to load second stage of Boot loader.

Partition table: MBR contains 64 bytes of data which stores Partition table information such as what is the start and end of each partition, size of partition, type of partition(Whether it’s a primary or extended etc). As we all know HDD support only 4 partitions, this is because of the limitation of its information in MBR. For a partition to represent in MBR, it requires 16 Bytes of space in it so at most we will get 4 partitions.

Magic Number: The magic number service as validation check for MBR. If MBR gets corrupted this magic number is used to retrieve it.

Once your CPU knows all these details, it will try to analyse them and read the first portion of MBR to load Second stage of Boot loader

136
Q

Stage 3. Bootloader part 2

A

Once the Bootloader stage 1 is completed and able to find the actual bootloader location, Stage 1 bootloader start second stage by loading Bootloader into memory. In this stage GRUB(Grand Unified Bootloader) which is located in the first 30 kilobytes of hard disk immediately following the MBR is loaded into RAM for reading its configuration and displays the GRUB boot menu (where the user can manually specify the boot parameters) to the user. GRUB loads the user-selected (or default) kernel into memory and passes control on to the kernel. If user do not select the OS, after a defined timeout GRUB will load the default kernel in the memory for starting it.

137
Q

Stage 4 of booting process - kernel

A

Once the control is given to kernel which is the central part of all your OS and act as a mediator of hardware and software components. Kernel once loaded into to RAM it always resides on RAM until the machine is shutdown. Once the Kernel starts its operations the first thing it do is executing INIT process.

138
Q

Stage 5 of boot process.

A

this is the main stage of Booting Process

init(initialization) process is the root/parent process of all the process which run under Linux/Unix. The first process it runs is a script at /etc/rc.d/rc.sysinit which check all the system properties, hardware, display, SElinux, load kernel modules, file system check, file system mounting etc. Based on the appropriate run-level, scripts are executed to start/stop various processes to run the system and make it functional. INIT process read /etc/inittab which is an initialization table which defines starting of system programs. INIT will start each run level one after the other and start executing scripts corresponds to that runlevel.

The script information is stored in different folders in /etc/ folder

Once the initialization process completes mandatory run level and reach to default runlevel set in /etc/inittab, init process run one more file /etc/rc.localwhich are the last commands run in initialization process or even booting process. Once everything is completed the control is given back to the kernel

139
Q

Stage 6 of unix boot process.

A

This is actually not part of booting process but thought of including it here for better understating. Once the Kernel get the control it start multiple instances of “getty” which waits for console logins which spawn one’s user shell process and gives you user prompt to login.

140
Q

What does the Bios do, exactly?

A

1.) Performs some system integrity checks

2.) Searches, loads,and executes the boot loader program.

141
Q

Tell me abut the MBR?

A
  1. It is located in the 1st sector of the bootable disk.
  2. MBR is less than 512 bytes in size. This has three components 1) primary boot loader info in 1st 446 bytes 2) partition table info in next 64 bytes 3) mbr validation check in last 2 bytes.
  3. It contains information about GRUB (or LILO in old systems).
142
Q

What are Vlads Bootup stages?

A
  1. BIOS (post)
  2. MBR
  3. BOOTLOADER (copies itself into high memory address)
  4. OS START-UP CODE(assembly code - setup kernal stack - identify ram type + amount)
  5. OS MAIN (c-language - allocate kernal data structures)
  6. PROCESS 0 (mount file system)
  7. PROCESS 1 & 2 (execute /etc/rc)
  8. GETTY (prepare for login)
143
Q

What is the history of Unix?

A

1969: Developed at AT&T Bell Labs in Murray Hill, New Jersey, one of the largest research facilities in the world. Created in an environment when most computer jobs were fed into a batch system.

Developed by researchers who needed a set of computing tools to help them with their projects and their collaborators. Allowed a group of people working together on a project to share selected data and programs.

1975: AT&T makes UNIX widely available - offered to educational institutions at minimal cost. Becomes popular with university computer science programs. AT&T distributes standard versions in source form: Version 6 (1975), Version 7 (1978), System III (1981).

1984 to date: University of California, Berkeley adds major enhancements, creates Berkeley Standard Distribution (BSD)

1984 to date: Many Berkeley features incorporated into new AT&T version: System V

UNIX has become the operating system of choice for engineering and scientific workstations.

Two variations maintain popularity today, AT&T System V based and the Berkeley Standard Distribution.

Current versions (1/95)are System V release 4.2 .and 4.4 BSD

Work is in progress to develop a Portable Operating System specification based on UNIX (IEEE POSIX committee).

144
Q

What is the Unix philosophy?

A
  • Make each program do one thing well. Reusable software tools: 1 tool = 1 function
  • Expect the output of every program to become the input of another, yet unknown, program to combine simple tools to perform complex tasks
  • Prototyping: get something small working as soon as possible and modify it incrementally until it is finished
  • Use terse commands and messages: reduces typing and screen output
145
Q

Describe the kernel in Unix.

A
  1. The core of the UNIX system.
  2. Loaded at system start up (boot). Memory-resident control program.
  3. Manages the entire resources of the system, presenting them to you and every other user as a coherent system.
  4. Provides service to user applications such as device management, process scheduling, etc.

Example functions performed by the kernel are:

  • managing the machine’s memory and allocating it to each process.
  • scheduling the work done by the CPU so that the work of each user is carried out as efficiently as is possible.
  • accomplishing the transfer of data from one part of the machine to another
  • interpreting and executing instructions from the shell

e
* forcing file access permissions

146
Q

What are the three file descriptors of a unix shell?

A
  1. Standard Input
  2. Standard output
  3. Standard error
147
Q

How are these different?

command > file

command >> file

A
  1. > sends the std output to a file
  2. >> appends the std output to a file
148
Q

How do you sendthe std-error of a command to a file?

A

command 2> file

149
Q
  1. command &> file …. does what?
A
  1. std-output and std-error both get dericted to a file
150
Q

Describe the kernel in Unix.

A

The kernel of UNIX is the hub of the operating system: it allocates time and memory to programs and handles the filestore and communications in response to system calls.

As an illustration of the way that the shell and the kernel work together, suppose a user types rm myfile (which has the effect of removing the file myfile). The shell searches the filestore for the file containing the program rm, and then requests the kernel, through system calls, to execute the program rm on myfile. When the process rm myfile has finished running, the shell then returns the UNIX prompt % to the user, indicating that it is waiting for further commands.

151
Q

Describe the shell component of unix

A
  • Whenever you login to a Unix system you are placed in a shell program.
  • The shell’s prompt is usually visible at the cursor’s position on your screen. To get your work done, you enter commands at this prompt.
  • The shell is a command interpreter; it takes each command and passes it to the operating system kernel to be acted upon.
  • It then displays the results of this operation on your screen.
  • Several shells are usually available on any UNIX system, each with its own strengths and weaknesses.
  • Different users may use different shells. Initially, your system adminstrator will supply a default shell, which can be overridden or changed.
  • The most commonly available shells are:
  • Bourne shell (sh)
  • C shell (csh)
  • Korn shell (ksh)
  • TC Shell (tcsh)
  • Bourne Again Shell (bash)
  • Each shell also includes its own programming language. Command files, called “shell scripts” are used to accomplish a series of tasks.
152
Q

Explain this:

command > file 2 >&1

A

The commands std-output is deirected to the file. The files std-errors toldtofollow it’s std-error which has already been direted to the file. Thus, std.error and the std.output areboth being directed tothe file.

153
Q

What is the Utilities component of Unix?

A

UNIX provides several hundred utility programs, often referred to as commands.

Accomplish universal functions

editing

file maintenance

printing

sorting

programming support

online info

etc.

Modular: single functions can be grouped to perform more complex tasks

154
Q

Does this send the st-error and std_output to a file? Elaborate..

command 2 >&1 > file

A

No. First it tells the std.err to follow the std.out so both are directed to te std.out. Then it directs this to the std.out to a file. However, the std.error is not directed to the file with the std.out

155
Q

How do you direct a file to a command as input?

A

command < file

156
Q

Files and Processes in Unix

A

Everything in UNIX is either a file or a process.

A process is an executing program identified by a unique PID (process identifier).

A file is a collection of data. They are created by users using text editors, running compilers etc.

Examples of files:

a document (report, essay etc.)

the text of a program written in some high-level programming language

instructions comprehensible directly to the machine and incomprehensible to a casual user, for example, a collection of binary digits (an executable or binary file);

a directory, containing information about its contents, which may be a mixture of other directories (subdirectories) and ordinary files.

157
Q

How do you direct multple lines to command as std.in?

A

command << EOL

multi-line

text

here

EOL

158
Q

Describe the Shell component of Unix OS.

A

The shell acts as an interface between the user and the kernel. When a user logs in, the login program checks the username and password, and then starts another program called the shell. The shell is a command line interpreter (CLI). It interprets the commands the user types in and arranges for them to be carried out. The commands are themselves programs: when they terminate, the shell gives the user another prompt (% on our systems).

The adept user can customise his/her own shell, and users can use different shells on the same machine. Staff and students in the school have the tcsh shellby default.

The tcsh shell has certain features to help the user inputting commands.

Filename Completion - By typing part of the name of a command, filename or directory and pressing the [Tab] key, the tcsh shell will complete the rest of the name automatically. If the shell finds more than one name beginning with those letters you have typed, it will beep, prompting you to type a few more letters before pressing the tab key again.

History - The shell keeps a list of the commands you have typed in. If you need to repeat a command, use the cursor keys to scroll up and down the list or type history for a list of previous commands.

159
Q

Whats happening here?

exec 2 > file

A

The std.err is being directed into the file forever..

160
Q

command | tee file

Explain?

A

This pipelines the std.out to the tee utility which splits it so that it is redirected to the std.in of the file AND the regular std.out.

161
Q

mkdir command

A

Make a directory

162
Q

chown command

A

chown is a command to change the ownership of a file/folder or even multiple files/folders at a time to a specified user/group. CHOWN stands for CHange file OWNer and Group.

163
Q

cd command

A

The command cd directory means change the current working directory to ‘directory’. The current working directory may be thought of as the directory you are in, i.e. your current position in the file-system tree.

164
Q

chgrp command

A

CHGRP(CHange GRouP) is one more command which is useful to change group associated to a file/folder from one group to other in a Linux box. This is sister command to chown which is used to change owner of the file/folder as well as group name associated with that file.

165
Q

pwd

A

Print the path of the current working directory

166
Q

mv file1 file2

A

To move a file from one place to another, use the mv command. This has the effect of moving rather than copying the file, so you end up with only one file rather than two.

167
Q

How are C source files transformed into an executable program?

A

First, source files are compiled if there are no errors. This creates an object file .o. Next, this object file is linked with other object files int eh standard library via the Linker. This creates an executable file.

168
Q

cat command

A

The command cat can be used to display the contents of a file on the screen.

169
Q

less command

A

The command less writes the contents of a file onto the screen a page at a time.

170
Q

head command

A

The head command writes the first ten lines of a file to the screen.

171
Q

tail command

A

The tail command writes the last ten lines of a file to the screen.

172
Q

grep command

A

grep is one of many standard UNIX utilities. It searches files for specified words or patterns.

173
Q

What does the C preprocessor do?

A

include – includes contents of a named file. Files usually called header files. e.g

The Preprocessor accepts source code as input and is responsible for

removing comments

interpreting special preprocessor directives denoted by #.

For example

174
Q

What does the C compiler do?

A

The C compiler translates source to assembly code. The source code is received from the preprocessor.

175
Q

What does the C assembler do?

A

The assembler creates object code. On a UNIX system you may see files with a .o suffix (.OBJ on MSDOS) to indicate object code files.

176
Q

What does the C link editor do?

A

If a source file references library functions or functions defined in other source files the link editor combines these functions (with main()) to create an executable file.

177
Q

Draw the C compilation model.

A
178
Q

C preprocessor

A

C provides certain language facilities by means of a preprocessor, which is conceptionally a separate first step in compilation. The two most frequently used features are #include, to include the contents of a file during compilation, and #define, to replace a token by an arbitrary sequence of characters. Other features described in this section include conditional compilation and macros with arguments.

179
Q

In the context of Unix server, what is meant by the acronym LAMP.

A
  1. Linux
  2. Apache
  3. MySQL, MariaDB, Mongo DB
  4. Php, Perl, Python
180
Q

Whats the main function of an OS?

A

To manage the resources of a computer: CPU, Memory, I/O Devices, Network.

181
Q

What does size_t define?

A

size_t is the unsigned integer type returned by the size_of operator

182
Q

argc

A

argument count: the number of parameters passed plus one to include the name of the program that was executed to get those process running. Thus, argc is always greater than zero and argv[0] is the name of the executable (including the path) that was run to begin this process.

183
Q

argv

A

argument vector: argv parameter is the array of character string of each command line argument passed to executable on execution.

184
Q

One of the basic services that the kernel provides is process management. What is process management?

A

Process management, possibly the most obvious aspect of a kernel to the user, is the part of the kernel that ensures that each process obtains its turn to run on the processor and that the individual processes do not interfere with each other by writing to their areas of memory. A process, also referred to as a task, can be defined as an executing (i.e., running) instance of a program.

185
Q

What does the kernel consist of?

A

The contents of a kernel vary considerably according to the operating system, but they typically include (1) a scheduler, which determines how the various processes share the kernel’s processing time (including in what order), (2) a supervisor, which grants use of the computer to each process when it is scheduled, (3) an interrupt handler, which handles all requests from the various hardware devices (such as disk drives and the keyboard) that compete for the kernel’s services and (4) a memory manager, which allocates the system’saddress spaces (i.e., locations in memory) among all users of the kernel’s services.

186
Q

What is the difference between the kernel and the BIOS?

A

The kernel should not be confused with the BIOS (Basic Input/Output System). The BIOS is an independent program stored in a chip on the motherboard (the main circuit board of a computer) that is used during the booting process for such tasks as initializing the hardware and loading the kernel into memory. Whereas the BIOS always remains in the computer and is specific to its particular hardware, the kernel can be easily replaced or upgraded by changing or upgrading the operating system or, in the case of Linux, by adding a newer kernel or modifying an existing kernel.

187
Q

Are kernels specific to the operating system?

A

Most kernels have been developed for a specific operating system, and there is usually only one version available for each operating system. For example, the Microsoft Windows 2000 kernel is the only kernel for Microsoft Windows 2000 and the Microsoft Windows 98 kernel is the only kernel for Microsoft Windows 98. Linux is far more flexible in that there are numerous versions of the Linux kernel, and each of these can be modified in innumerable ways by an informed user.

A few kernels have been designed with the goal of being suitable for use with any operating system. The best known of these is the Mach kernel, which was developed at Carnegie-Mellon University and is used in the Macintosh OS X operating system.

188
Q

What are two main components of the kernel?

A
  1. File System
  2. Process Control
189
Q

What are the categories of Kernel types?

A

Kernels can be classified into four broad categories: monolithic kernels, microkernels, hybrid kernels and exokernels. Each has its own advocates and detractors.

190
Q

What part of the O.S. interfaces directly with the hardware.

A
  1. The Kernel
191
Q

Describe Monolithic kernels.

A

Monolithic kernels, which have traditionally been used by Unix-like operating systems, contain all the operating system core functions and the device drivers (small programs that allow the operating system to interact with hardware devices, such as disk drives, video cards and printers). Modern monolithic kernels, such as those of Linux and FreeBSD, both of which fall into the category of Unix-like operating systems, feature the ability to load modules at runtime, thereby allowing easy extension of the kernel’s capabilities as required, while helping to minimize the amount of code running in kernel space.

192
Q

What three types ofmanagement is the Kernel concerned with:

A
  1. Process Management
  2. Device Management
  3. File Management

P.S. It’s also responsible for

  1. Networking
  2. Networking File Systems
  3. Virtual Memory
193
Q

What is the microkernel type?

A

A microkernel usually provides only minimal services, such as defining memory address spaces, interprocess communication (IPC) and process management. All other functions, such as hardware management, are implemented as processes running independently of the kernel. Examples of microkernel operating systems are AIX, BeOS, Hurd, Mach, Mac OS X, MINIX and QNX.

194
Q

Name one way in which the Kernel controls accesstothe cpu?

A

By listening for Interrupt requests and stopping/starting programs accordngly, the Kernel controls and priotitizes access tothe cpu.

195
Q

What is the Hybrid kernel type?

A

Hybrid kernels are similar to microkernels, except that they include additional code in kernel space so that such code can run more swiftly than it would were it in user space. These kernels represent a compromise that was implemented by some developers before it was demonstrated that pure microkernels can provide high performance. Hybrid kernels should not be confused with monolithic kernels that can load modules after booting (such as Linux).

196
Q

Describe the exokernel type.

A

Exokernels are a still experimental approach to operating system design. They differ from the other types of kernels in that their functionality is limited to the protection and multiplexing of the raw hardware, and they provide no hardware abstractions on top of which applications can be constructed. This separation of hardware protection from hardware management enables application developers to determine how to make the most efficient use of the available hardware for each specific program.

Exokernels in themselves they are extremely small. However, they are accompanied by library operating systems, which provide application developers with the conventional functionalities of a complete operating system. A major advantage of exokernel-based systems is that they can incorporate multiple library operating systems, each exporting a different API (application programming interface), such as one for Linux and one for Microsoft Windows, thus making it possible to simultaneously run both Linux and Windows applications.

197
Q

What isa process?

A

A process is an instance of the program in execution.

198
Q

What do the following system resources do?

  1. Fork
  2. Wait
  3. Exec
  4. Exit
A
  1. Fork: creates a new process
  2. Wait: Allow a parent process to syncyronize its execution with the exit of a child process
  3. Exec: invokes a new program
    4: Exit: terminates process executation.
199
Q
A
200
Q

How does a user create a new process in Unix.

A

Fork() is the only way to create a new process in Unix.

201
Q

Describe the shell component of the Unix architecture.

A

A shell is a program that provides the traditional, text-only user interface for Linux and other Unix-like operating systems. Its primary function is to read commands that are typed into a console (i.e., an all-text display mode) or terminal window (an all-text window) in a GUI (graphical user interface) and then execute (i.e., run) them.

The term shell derives its name from the fact that it is an outer layer of an operating system. A shell is an interface between the user and the internal parts of the operating system (at the very core of which is the kernel).

A user is in a shell (i.e., interacting with the shell) as soon as that user has logged into the system. A shell is the most fundamental way that a user can interact with the system, and the shell hides the details of the underlying operating system from the user.

202
Q

What are some of the functions of the Shell?

A

Shells, although small in size, are sophisticated and powerful programs that are used for the following: program execution (i.e., launching), substitution of variables and of file names, input/output (I/O), redirection (i.e., sending the output from a program to a destination other than its default destination, including to be used as the input for another program), user environment control (e.g., changing the shell or the shell prompt), and serving as a programming language (i.e., a language that can be used to write shell scripts). Shells in Unix-like operating systems are unusual in that they are both an interactive command language (i.e., a language that a user can employ interactively to issue commands)and a programming language.

203
Q

Briefly describe fork()?

A

Fork is a system call that is required to in order to make a new process. The syntax of the system call is thus:

newpid = fork()

Forking creates an identical process to the parent process called the child process. The child is only different becuase of it’s new PID. In unix all processes are children of the init process.

204
Q

GUI in Unix systems

A

However, GUIs are merely front ends for shells; that is, they are merely attractive interface layers that are built on top of a shell and which use the shell’s commands. As shells are usually more powerful and feature-rich than GUIs, most intermediate and advanced users of Unix-like operating systems find them to be preferable to GUIs for many tasks.

205
Q

Describe the sh shell?

A

sh (the Bourne Shell) is the original UNIX shell, and it is still in widespread use today. Written by Stephen Bourne at Bell Labs in 1974, it is a simple shell with a small size and few features, perhaps the fewest of any shell for a Unix-like operating system. Bell Labs was the research and development arm of AT&T (The American Telephone and Telegraph Company), the former U.S. telecommunications monopoly. The first version of UNIX was developed at Bell Labs in 1969.

Among the functions that most users have come to expect in a shell but which are missing in sh are file name completion, command editing, command history and ease of executing multiple background processes (also referred to as jobs). A process is an instance of an executing program; a background process operates generally unnoticed while users are working with foreground processes. File name completion is the completion by the system of the names of files that have only partially typed in by a user. Command history allows users to conveniently find and reissue previously issued commands. Every Unix-like system contains sh or another shell which incorporates its commands.

206
Q

Describe the bash shell.

A

bash (Bourne-again shell) is the default shell on Linux. It also runs on nearly every other Unix-like operating system as well, and versions are also available for other operating systems including the Microsoft Windows systems. Bash is a superset of sh (i.e., commands that work in sh also work in bash, but the reverse is not always true), and it has many more commands than sh, making it a powerful tool for advanced users. But it is also intuitive and flexible, and thus it is probably the most suitable shell for beginners. bash was written for the GNU project (whose goal is to develop a complete, Unix-compatible, high performance and entirely free operating system), primarily by Brian Fox and Chet Ramey. Its name is a pun on the name of Steve Bourne.

207
Q

The Kernel assigns PID’s whenever a process is created. Processes can obtain their PID by calling getpid().

But how do proceses obtaintheir parents PID?

A

getppid()

208
Q

Describe the ash shell

A

ash (the Almquist shell) is a clone of sh that was written by Kenneth Almquist in 1989. It is the shell that is the most compliant with sh, and it does not have any additional functions that other interactive shells such as bash and tcsh offer. ash also features small memory requirements compared to the other sh-compliant shells and is thus well suited for systems with small memories, especially small embedded systems (i.e., systems built into other products). It is available on most commercial Unix-like systems.

209
Q

What value does fork return for a child process?

A

0

210
Q

Describe the csh shell.

A

csh (the C shell) has a syntax that resembles that of the highly popular C programming language (also developed at Bell Labs), and thus it is sometimes preferred by programmers. It was created in 1978 by Bill Joy (who also wrote the vi text editor and later co-founded Sun Microsystems) at the University of California at Berkeley (UCB).

211
Q

Describe the ksh shell

A

ksh (the Korn shell) is a superset of sh developed by David Korn at Bell Labs in 1983. It contains many features of the C shell as well, including a command history, which was inspired by the requests of Bell Labs users. It also features built-in arithmetic evaluation and advanced scripting capabilities similar to those found in powerful programming languages such as awk, sed and perl.

212
Q

Describe the tcsh shell.

A

tcsh (the TENEX C shell) is based on csh but also has programmable file name completion, command line editing, a command history mechanism and other features lacking in csh. It is named after the TENEX operating system, which inspired the author of tcsh. tcsh replaced the csh as the default shell on some BSD operating systems (i.e., FreeBSD and Darwin).

213
Q

Describe the zsh shell.

A

zsh (the Z shell) is similar to ksh, but it also includes many features from csh. That is, it attempts to combine the programmability and syntax of the Korn shell with useful features from the C shell (which has some disadvantages as a programming language). It was written by Paul Falstad around 1990.

214
Q

What is a process

A

A process is an executing (i.e., running) instance of a program. Processes are also frequently referred to as tasks.

215
Q

What is a program?

A

A program is an executable file that is held in storage. Storage refers to devices or media that can retain data for relatively long periods of time (e.g., years or even decades), such ashard disk drives (HDDs), optical disks and magnetic tape. This contrasts with memory, whose contents can be accessed (i.e., read and written to) at extremely high speeds but which are retained only temporarily (i.e., while in use or only as long as the power supply remains on).

216
Q

What is an executable file?

A

An executable file is a binary file (i.e., a file at least part of which is not plain text) that has been compiled (i.e., converted using a special type of program called a compiler) fromsource code into machine machine code, which is a pattern of bytes that can be read directly by a central processing unit (CPU). Source code is the version of software as it is originally written (i.e., typed into a computer) by a human in plain text (i.e., human readable alphanumeric characters). A CPU is the main logic unit of a computer.

217
Q

More on processes.

A

A program is a passive entity until it is launched, and a process can be thought of as a program in action. Processes are dynamic entities in that they are constantly changing as their machine code instructions are executed by the CPU. Each process consists of (1) system resources that are allocated to it, (2) a section of memory, (3) security attributes (such as itsowner and its set of permissions) and (4) the processor state.

The processor state includes the contents of its registers and physical memory addresses. Registers are a very small amount of very fast memory that is built into a processor in order to speed up its operations by providing quick access to commonly used values. A memory address is a location in memory.

An alternative definition of a process is the execution context of a running program, i.e., all of the activity in the current time slot in the CPU. A time slot, also called a time slice or a quantum, is the length of time that each process is permitted to run in the CPU until it is preempted (i.e., replaced) by another process in a time sharing operating system.

218
Q

What is the difference between programs and processes?

A

Programs and processes are distinct entities. Thus, in a multitasking operating system, multiple instances of a single program can be executing simultaneously, and each instance is a separate process (or processes). For example, if seven users, each with their own keyboard and display device, decide to run the vi text editor at the same time, there will be seven separate instances of vi, each a separate process, although they will all share the same executable file. A single user can likewise simultaneously run seven instances of vi, or some other program.

Another, compatible, definition of a process, for those familiar with the C programming language (in which the kernels and numerous other programs in Unix-like operating systems are written), is the collection of data structures that completely describe how far the execution of the program has progressed. A data structure is a way of storing data in a computer so that it can be used efficiently.

219
Q

init process

A

The role of init is to read the entries in the file /etc/inittab and execute various programs according to that file. This includes starting the getty process on each of the login terminals, which eventually provides the designated shell for each user.

220
Q

PID

A

In Unix-like operating systems, each process is given a unique number, referred to as a process identification (PID), when it is created, and this number is used by the system to reference the process. Each process is guaranteed to have a unique PID, which is always a non-negative integer. init always has a PID of 1 because it is always the first process on the system. A very large PID does not necessarily mean that there are anywhere near that many processes on a system, because such numbers are often a result of the fact that PIDs are not immediately reused in order to prevent possible errors.

221
Q

What is a system call?

A

While a process is running, it can spawn (i.e., give birth to) other processes. Spawning is accomplished through the use of a system call termed a fork (because it splits in two). System calls are clearly defined, direct entry points into the kernel through which processes request services from the kernel.

222
Q

What is it, really?

A

a set of routines that resides continuously in memory and to which all processes have access.

223
Q

ps -aux | less

what it does, huh?

A

The -a option tells ps to list the processes of all users on the system rather than just those of the current user. The -u option tells ps to provide detailed information about each process. The -x option adds to the list processes that have no controlling terminal, such as daemon that are started during booting. In contrast to most commands, the hyphen preceding the option(s) with ps is optional.

224
Q

What information does ps aux provide?

A

Among the information that ps aux provides about each process is the user of the process, the PID, the percentage of CPU used by the process, the percentage of memory used by the process, VSZ (virtual size in kilobytes), RSS (real memory size or resident set size in 1024 byte units), STAT (the process state code), the starting time of the process, the length of time the process has been active and the command that initiated the process. The process state codes include D, uninterruptable sleep; N, low priority; R, runnable (on run queue); S, sleeping; T, traced or stopped; and Z, defunct (zombie).

225
Q

What are daemons?

A

Daemons are a class of processes that run continuously in the background, rather than under the direct control of a user. The term is derived from the ancient Greek word daimon, which refers to a supernatural being that is intermediate between a human and a god, or similar to a guiding spirit. Daemons are generally easy to recognize because their names end with the letter d.

Daemons are usually launched automatically while a computer is booting up and then wait in the background until their services are required. They typically respond to hardware activity, to network requests or to other programs by performing specified tasks. They can also configure hardware (such as the daemon devfsd, which can provide intelligent management of device entries in the device filesystem on some Linux systems), run scheduled tasks (e.g., crond) and perform a variety of other functions.

On the Microsoft Windows operating systems, functions comparable to those of daemons are provided by processes called services. However, the term daemon is now sometimes used with regard to those operating systems as well.

226
Q

What are filesystems in Unix?

A

The term filesystem has two somewhat different meanings, both of which are commonly used. This can be confusing to novices, but after a while the meaning is usually clear from the context.

One meaning is the entire hierarchy of directories (also referred to as the directory tree) that is used to organize files on a computer system. On Linux and Unix, the directories start with the root directory (designated by a forward slash), which contains a series of subdirectories, each of which, in turn, contains further subdirectories, etc.

A variant of this definition is the part of the entire hierarchy of directories or of the directory tree that is located on a single partition or disk. (A partition is a section of a hard disk that contains a single type of filesystem.)

The second meaning is the type of filesystem, that is, how the storage of data (i.e., files, folders, etc.) is organized on a computer disk (hard disk, floppy disk, CDROM, etc.) or on a partition on a hard disk. Each type of filesystem has its own set of rules for controlling the allocation of disk space to files and for associating data about each file (referred to as meta data) with that file, such as its filename, the directory in which it is located, its permissions and its creation date.

227
Q

Difference between root and ‘/’

A

The meaning of root and “/” are often confusing to new users of Linux. This because each has two distinct usages. The other meaning of root is a user who has administrative privileges on the computer, in contrast to ordinary users, who have only limited privileges in order to protect system security. The other use of “/” is as a separator between directories or between a directory and a file, similar to the backward slash used in MS-DOS.

228
Q

/bin

A

command binaries for all users

229
Q

/boot

A

boot loader files such as the kernel

230
Q

/home

A

users home directories

231
Q

/mnt

A

for mounting a CDROM or floppy disk

232
Q

/root

A

home directory for the root user

233
Q

/sbin

A

executables used only by the root user

234
Q

/usr

A

where most application programs get installed

235
Q

What is a System Call?

A

A system call, sometimes referred to as a kernel call, is a request in a Unix-like operating system made via a software interrupt by an active process for a service performed by the kernel.

236
Q

What’s a software interrupt?

A

A software interrupt, also called an exception, is an interrupt that is caused by software, usually by a program in user mode.

An interrupt is a signal to the kernel (i.e., the core of the operating system) that an event has occurred, and this results in changes in the sequence of instructions that is executed by the CPU (central processing unit). One of the two main types of interrupts, a hardware interrupt, is a signal to the system from an event that has originated in hardware, such as the pressing of a key on the keyboard, a movement of the mouse or a progression in the system clock.

Software interrupts were introduced into Linux with the 2.4 kernel. Examples of events that cause them are requests by an application program for certain services from the operating system or the termination of such programs. When it receives a software interrupt signal, the CPU may temporarily switch control to an interrupt handler routine, and theprocess (i.e., a running instance of a program) in the kernel that was suspended by the interrupt will be resumed after the interrupt has been accommodated. Each type of software interrupt is associated with an interrupt handler, which is a software routine that takes control when the interrupt occurs.

237
Q

What value does fork return for a parent process?

A

The pid of the process

238
Q

Is the PID of a child process zero or is it something else?

A

The childs PID is it’s unique PID. Zero is just a vaue that fork() returns to distinguish it from it’s identical parent.

239
Q

What is an interrupt?

A

An interrupt is a signal to the kernel that an event has occurred, and this results in changes in the sequence of instructions that is executed by the CPU.

240
Q

What is a software interrupt?

A

A software interrupt, also referred to as an exception, is an interrupt that originates in software, usually by a program in user mode.

User mode is one of two distinct execution modes of operation for the CPU in Linux. It is a non-privileged mode in which each process starts out. It is non-privileged in that processes in this mode are not allowed to access those portions of memory that have been allocated to the kernel or to other programs.

241
Q

In the gcc command what does this option mean

-Wall

A

Show all warnings

242
Q
A
243
Q

What’s a system call?

A

System calls can also be viewed as clearly-defined, direct entry points into the kernel through which programs request services from the kernel. They allow programs to perform tasks that would not normally be permitted.

Examples of the services performed by the kernel include as input/output (I/O) and process creation. The former can be defined as any movement of data to or from the combination of the CPU and main memory (i.e. RAM), that is, communication between this combination and the computer’s users (e.g., via the keyboard or mouse), its storage devices (e.g., disk or tape drives) or other computers. Process creation is the creation of a new process.

244
Q

In the gcc command what does the following option mean?

-O

A

Optimize the code

245
Q
A
246
Q
A
247
Q

What is the root user?

A

root is the user name or account that by default has access to all commands andfiles on a Linux or other Unix-like operating system. It is also referred to as theroot account, root user and the superuser.

248
Q

/root

A

Another is /root (pronounced slash root), which is the root user’s home directory. A home directory is the primary repository of a user’s files, including that user’s configuration files, and it is usually the directory in which a user finds itself when it logs into a system. /root is a subdirectory of the root directory, as indicated by the forward slash that begins its name, and should not to be confused with that directory. Home directories for users other than root are by default created in the/home directory, which is another standard subdirectory of the root directory.

249
Q

What is the Unix filesystem?

A

the entire hierarchy of directories that is used to organize files

250
Q

What does /etc/passwd store?

A

configuration file for user data

251
Q

/sbin

A

Contains command executable only by system admin. e.g. iptables, reboot, fdisk, ifconfig

252
Q
A
253
Q

/opt

A

Contains add-on applications from individual vendors

254
Q

/mnt

A

This is where additional filesystems can mount temporarily

255
Q

/media

A

Similar to /mnt, but this is for external removable devices

256
Q

stdout

A

Standard output, sometimes abbreviated stdout, refers to the standardized streams of data that are produced by command line programs (i.e., all-text mode programs) in Linux and other Unix-like operating systems.

257
Q

Redirection operators

A

Redirection operators can be used to redirect the output of a command line program from the display screen to a file where it is written and saved, to a printer where it is printed, or to another program where it is used as an input. In the following example the output redirection operator, which is represented by a rightward pointing angular bracket, is used to redirect head’s output from the display screen to a file named file2:

head file1 > file2

That is, the output from file1 is written to file2 instead of being displayed on the screen. The output redirection operator will cause the contents of file2 to be overwritten if a file with the same name already exists, and it will create a file with that name if it does not yet exist.

258
Q

stdin

A

Standard input, often abbreviated stdin, is the source of input data for command line programs (i.e., all-text mode programs) on Linux and other Unix-like operating systems.

Such operating systems feature the concept of standard streams of data. Each command, and therefore each process, is automatically initialized with (i.e., assigned) three data streams: one input stream, called standard input, and two output streams, called standard output and standard error. These streams consist of data in plain text (i.e., human readable alphanumeric characters) form and are considered to be special types of files.

Standard input is by default any text entered from the keyboard. It is the counterpart of standard output and standard error, which are by default the display monitor.

259
Q

stderr

A

Standard error, abbreviated stderr, is the destination of error messages from command line (i.e., all-text mode) programs in Unix-like operating systems.

260
Q

command &> file1

A

Redirection of stderr to where stdout is headed (file1)

261
Q

tee command

A

Tee command is used to store and view (both at the same time) the output of any other command.

Tee command writes to the STDOUT, and to a file at a time as shown in the examples below.

262
Q

$$

A

Process number of shell

263
Q

What is the C compilation model?

A
264
Q

Console vs. Terminal vs. Shell

A

The console refers to a screen and keyboard that are directly connected to the computer system. Usually, the console is positioned in the same physical room as the computer’s cabinetry. Even without any network connectivity, the console is available for use by the system’s administrator.

A terminal artificially emulates the physical hookup of a console. Many users may open terminal programs on their own computers to connect to a central server over the network. One user may use multiple terminal programs to view multiple sessions, even on the same console. The terminal just provides a communication channel for the user’s input and output.

Once the ability to type input and see the computer’s output has been established with a console or terminal, the next concept is for the computer to run a command shell. A command shell, or just ‘shell’ for short, is a program that runs on the computer that offers a command line interface to the user. It listens to the user’s typed commands, parses them, executes them, and then formats and displays the output back across to the user. Shells just prompt for commands, listen for commands, process commands, and prompt for more commands, endlessly repeating until the terminal is closed or the user logs out.

265
Q

What is the history of the OSI model?

A

The Open Systems Interconnection model (OSI) is a conceptual model that characterizes and standardizes the internal functions of a communication system by partitioning it into abstraction layers. The model is a product of the Open Systems Interconnection project at the International Organization for Standardization (ISO)

266
Q
A
267
Q

POSIX

A

Portable Operating System Interface (POSIX) released in 1988

POSIX is a family of standards, specified by the IEEE, to clarify and make uniform the application programming interfaces (and ancillary issues, such as commandline shell utilities) provided by Unix-y operating systems.