Final Superdeck Flashcards

1
Q

3 special files with commands

A

stdin
stdout
stderr
0, 1, 2, respecitively

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

List of special/default directories.

A

/bin
/sbin
/lib
/usr
/etc
/home
/boot
/dev
/opt
/var
/tmp
/proc

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

/bin

A

binaries or executables. System programs like gcc, vim. Essential for the operation of the system itself.

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

/sbin

A

System binaries that should only be executed by the root (admin) user.

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

/lib

A

Libraries

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

/usr

A

user binaries, libraries, etc.

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

/etc

A

Editable text configurations, where configuration files are found

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

/home

A

User home (or personal) directories are here.

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

/boot

A

contains files needed to boot the system like the OS kernel

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

/dev

A

Device files. Allows interfacing with I/O devices with special files that are mapped to directories.

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

/opt

A

Optional software. Rarely used.

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

/var

A

Variables files that are changed as the system operates. Like log files.

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

/tmp

A

Temporary files not persisted between system rebootst.

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

/proc

A

An imaginary directory made by the kernel to keep track of processes.

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

How to go to home directory?

A

~ (tilde)

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

What does cat do?

A

Takes in a file as an argument, and outputs the contents to stdout. If a file is not given, it takes from stdin.

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

How to EOF in a command?

A

ctrl-d

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

What does > do in Bash?

A

Output redirection.
Redirects outputs of a command to a file.
Note that > creates (or overwrites).
» creates (or appends)

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

What does < do in bash?

A

Input redirection.
Tells the shell to get the input for a command from a specified file instead of a keyboard.
I.e.
command [arguments] < filename

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

Pipelines

A

Take stdout prior command and uses it as stdin to another.

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

How to increment a number (variable) in bash?

A

let x=x+1

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

Bash if else

A

if test-command
then
commands
elif test-command
then
commands
else
commands
fi

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

Bash while

A

while test-command
do
commands
done

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

Assembly is a ___ level language.

A

Low-level, since there is a 1-to-1 correspondence between statements and machine instructions.
Assembly is also machine dependent.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What does the OS do?
Controls the entire operation of the system. All input and output performed on a computer system are channeled through the OS.
26
Steps to getting an executable from source code.
Pre-processor takes and expands symbol definitions. Inserts header file text. Compiler - Syntactically correct programs are translated into a lower form, assembly. Assembler - Translates assembly language statements into actual machine instructions (object code or .o files). Linker - links all object files together with system libraries to produce an executable file.
27
Building
Compiling/linking a program. Leads to an executable.
28
Parts of a makefile.
target dependencies recipe recipe must be tab-indented
29
Integer format character
%i or %d (d for decimal, i detects base) or %o or %x for octal and hexadecimal
30
int minimum size
Guaranteed to be no smaller than 16 bits
31
Float format specifier
%f or %e for exponential notation
32
In class, how many bits were floats and doubles?
Float: 32 Double: 64
33
How to make a constant (literal) long int?
Append an L on the end.
34
Unsigned int format specifier.
%u
35
Short- format specifier
%h
36
int to float and vice versa?
Floats are truncated (i.e 3/2 is 1). Ints have no change.
37
Control structures with only 1 line
Simply omit curly braces. Ends at the semi-colon.
38
do while
do statement; while (condition); or do { statements; } while (condition);
39
if else with single lines?
if (condition) statement; else statement;
40
C switch case.
switch (expression) { case value1: statement1; .... statementn; break; case value2: statement1; .... statementn; break; default: statement1; .... statementn; break; } Note: ONLY WORKS FOR INTEGER TYPES i.e. int, short, long, long long, char...
41
Ways to initialize arrays.
type name[N] = ... {1, 2, 3, 4,...} initialize in order (doesn't have to be all of them) or {[0] = 1, [2] = 3,...} specific indices
42
In C, strings are...
Just char arrays. Must always end with null-terminator (sometimes called zero-terminator).
43
Defining a multidimensional array in C
type name[n][m] Notes: int A[2][2] = {1 2 3 4} is equivalent to { {1,2}, {3,4}} (but not recommended). can also do int A[2][2] = {[1][0]=3, [2][2]=4};
44
Variables passed to a function are passed...
By value. This means that giving it an int x gives it an equivalent value, but not x. However, giving it a pointer to x lets it access the value at the pointer to change x.
45
Global variables.
Outside of other scopes. I.e. same scope as the include statements.
46
Multidimensional arrays implicit size.
Cannot be explicit, aside from first. I.e. A[][] is invalid. A[10][10] is valid A[][10] is valid
47
What do git commits include?
added/removed files files renamed/moved insertions/deletions in a file (lines changed) timestamp user message more...
48
CFLAGS we use
-Wall -Werror -std=c99 -pedantic -g
49
-Wall
Enables all warnings. can catch questionable constructions.
50
-Werror
Turns warnings into errors. Forces you to fix questionable code.
51
-std=
Selects a specific standard. Standards keep things portable.
52
-pedantic
Issue all warnings demanded by strict C standard.
53
-g
Generate a debugging section in the executable. Needed to use gdb
54
How to reference a Makefile variable?
$(VAR)
55
Useful gdb commands
step next (may jump over one line loops, function calls, etc). info break (list and give info about breakpoints). clear line-or-funciton-name (removes a breakpoint) delete breakpoints (duh) info locals set var x=2 (sets a variables value) bt (stacktrace (backtrace). useful when many functions)
56
Structs without names
struct { stuff; } var_name = {stuff}; Note, could use commas on the last line to declare many variables. This is not recommended.
57
Program memory layout.
Top to bottom. (high to low address) Command line arguments. Stack Heap Uninitialized data segment initialized data segment text/code segment Dynamic includes from command line arguments to heap. Static elsewhere.
58
What is the text segment in program memory?
Instructions reside here.
59
What is initialized data segment in program memory?
Holds literals and constants.
60
What is uninitialized data segment in program memory?
Contains static and global variables.
61
What is the stack in program memory?
Only can push and pop, which makes stack perfect for nested scopes (functions calling functions).
62
What happens in program memory when a function is called?
An entry is pushed onto the stack including arguments, space for automatically allocated variables inside the function, and a return address. Once done, it's popped from the stack.
63
What is a stack overflow?
When the stack overflows. i.e. too many recursive functions. The stack runs out of space, or runs into the heap.
64
What is the heap used for in program memory?
Dynamic memory allocation.
65
What happens when a C program is compiled and run?
From high level language, compiler translates to assembly. Assembler then translates to machine code to make an object file. Linker combines objects and libraries, resolves references, and makes an executable. Finally, the loader loads the executable into a suitable memory location and begins execution (which may involve more linking during runtime).
66
What is a process?
An OS concept that can be though of as a container for a single executable. Programs usually only have 1 process, but they could have many. There can be many running processes at the same time. The OS provides a method to switch between them (scheduling).
67
What is a thread?
A path of execution. One process can have one or many threads. Many threads can run at any given time. Like processes, they are scheduled by the OS or within each process. Each thread will need its own stack if multiple in a program.
68
Where do commands live?
Most in standard directories; /bin, /usr/bin, usr/local/bin, /opt/X11/bin Some commands aren't binaries, but are shell programs.
69
How can you find where a binary, header, or source file, is?
locate command
70
How can you find where a command binary/shell-script is?
Use which or whereis command
71
What does char * const charPtr = &c; do?
Makes a constant pointer. c can change, but charPtr will always point to it.
72
What does const char *charPtr = &c; do?
Notes that the contents of &c do not change, although charPtr can change.
73
What does const char * const charPtr = &c; do?
Makes the pointer and the value both constant.
74
How do you make a pointer to an array?
Make it point to the type held by the array. I.e. A pointer to an int array is the same as a pointer to an int.
75
What does the name of an array do without any other operators?
Represents the pointer.
76
Can pointers be compared?
Yes. This can be useful at times, for example when checking if something may exceed the bounds of an array.
77
Function pointer variable declaration syntax.
return-type (*pointer-var-name) (arg-type1, ...); i.e. int (*fnPtr) (void);
78
How are who can access a file controlled?
Traditional access permissions and ACLs (Access Control Lists).
79
Three types of users who can access a file.
The owner of the file (owner/user), a member of a group that the file is associated with (group), everyone else (other)
80
Three ways an ordinary file can be accessed
read form it write to it execute it
81
How to see permissions?
ls -l
82
What is the first bit that comes before permissions?
- for ordinary files d for directories
83
How to use chmod?
symbolic arguments i.e. chmod a+rw gives (+) read-write (rw) permissions to all users (a). Also can use o (other) g (group) u (user or owner)
84
chmod numeric arguments
just give it an octal number. i.e. chmod 600 somefile somefiles permissions would be rw------- Note that this sets permissions.
85
Who can access any file on the system?
A user with root privileges. Note that if something is encrypted, they may not be able to understand what's in a file anyways.
86
What does read write and execute mean for directories?
read - list contents write - add new files/subdirectories to it execute - lets user cd into it
87
What are ACLs good for?
Finger-grained control over which users can access specific directories or files. Note that ACLs must be enabled for the system. Note that not all utiliites preserve ACLs when moving, copying, or archiving. Note that ACLs are not recommended on system files where traditional permissions are sufficient due to performance reasons.
88
What is a file link?
A pointer to a file.
89
How to create a hard link to an existing file?
ln existing-file new-link The absence of the -s or --symbolic option means it makes a hard link and not a symbolic link.
90
What is a hard link?
Appears as another file. Must have a different name if in the same directory. Can only make a hard link from within the filesystem that holds the file. Editing the file from any hard link edits the same file. All hard links are of equal value. As long as one hard link remains, the file exists. It is removed when all hard links disappear.
91
What is a symbolic link.
A pointer to a file. Indirect (like a double pointer). Contains the pathname of the pointed-to file. Can link to non-existent files, files on different file systems, link to a directory (unlike a hard link).
92
ls
list directory contents
93
mkdir
make a directory
94
rmdir
rmdir remove an empty directory
95
cp
copy files
96
mv
move or rename files
97
rm
delete files/directories (rm -r for non-empty directories)
98
ln
create links between files
99
file
determine file type
100
stat
display file status
101
chmod
change access permissions
102
chgrp
change group of a file/dir
103
chown
change owner of a file/dir (admin only)
104
Process structure
Like a file structure, the process structure is hierarchical with parents, children, and a root. A parent process forks (or spawns) a child process, which in turn can fork other processes. Initially, the forks are identical, but one is identified as a parent, and the other the child. fork()
105
What is the init daemon?
A Linux system begins execution by starting the init daemon, a single process (called a spontaneous process) with PID 1. The ancestor of all processes the system and users work with.
106
Process structure, login
When a system is in multi-user mode, init (recall the init daemon) calls getty or mingetty processes that display logic prompts on terminals and virtual consoles. Then, when a user responds (and pushes RETURN), getty or mingetty passes control to the login utility, that checks the user-name and password. After that, the login process becomes the user's shell process.
107
What happens when the name of a program is given to the command line?
The shell forks (fork()) a new process, which create a duplicate of the shell (a subshell). Recall how fork makes a parent and child process. The new process attempts to exececute (exec()) the program. exec() causes a process's image (the entire memory layout) to be replaced by that of a different executable file (invoking the loader of the system). Remember: fork() exec() load
108
enums
enum nameofnewtype { list, of, permissible, identifiers } can then assign values like enum nameofnewtype varname = permisible; and do things like if (varname == of)
109
How are enumeration identifiers treated internally?
The C compiler treats them as integer constants. Each name sequentially assigned an integer starting with 0. Note that you can manually control these too. i.e. enum whatever { thingone, thingtwo = 42, thingthree }; Note that thingthree then gets value 43. Can use type cast operators to cast integers to enums. i.e. thisMonth = (enum month) (monthValue - 1); makes thisMonth 1 less than monthValue.
110
Unnamed enumerated data types?
enum {thing1, thing2, thing3...} varname;
111
typedef
Lets you assign an alternate name to a data type. i.e. typedef int Counter; defines the name Counter to be equivalent to int. Some uses beyond readability. i.e. typedef char Linebuf[81]; defines an array of 81 chars, so Linebuf text; is equivalent to char text[81];
112
How to use typedef?
Write a statement as if declaring a variable of the underlying type. Write the name of the type definition where the variable name would normally be. Put typedef in front of everything. i.e. typedef struct { int a; int b; } nameofnewtype;
113
How are preprocessor statements identified?
By the # sign which must be the first non-space character on the line. Note that their syntax differs.
114
The define statement.
#define ABCDEF GHIJKL would replace all instances of ABCDEF with GHIJKL. ABCDEF is the name, GHIJKL is the value. Note that this doesn't apply to the inside of character strings. Note that this is a text replacement, not a variable. Conventionally, #define names are in capital letters to distinguish them.
115
Reasons to divide a program into many files.
It takes longer to compile a larger file. Larger programs often take the efforts of many programmers. A single source file can become unmanageable.
116
What is gcc?
A C preprocessor, C compiler, and linker.
117
What does gcc -c do?
Performs steps 1-3. It doesn't link files together. To link them together, omit the -c.
118
When does a file need to include a header file?
When it uses, or implements the functions listed in a particular header file.
119
What does the #include statement do?
It asks the C preprocessor to literally "include" the code found.
120
Difference between <...> and "..." in an include statement.
<...> tells the preprocessor to search system locations. Usually for standard libraries and libraries your program builds. "..." tells the preprocessor to search first in the current directory, and then in system locations. This is usually used for header files local to your project.
121
How do you add a place to search to the preprocessor's list?
-I (capital i) and a directory. i.e. -I/abs/path/to/project -I. for example tells it to consider the current directory in its list of places to search.
122
How does -I behave differently between the <> and "" versions of #include?
-I checks given path before system paths with <>. -I checks the current directory, then the given path, then system paths.
123
Were does the -I option go in a makefile?
CPPFLAGS
124
How to link a static library together?
ar rcs libname.a mod1.o mod2.o... Makes a static library called libname.a that contains mod1.o mod2.o...
125
How must libraries be named?
Must start with lib, and end with .a for static or .so for dynamic.
126
How do you link a dynamic library?
Use the -L and -l (lowercase L) opinions when invoking gcc in the linking step. -L followed by a directory (like -L/home/pathstuff) says where to look for library files. -I (like -Inameoflib) tells gcc to link a specific library from one of the locations given by -L. For example, -larrayutil (looks for libarrayutil.a)
127
Where to put -L and -I (lowercase L)
LDFLAGS
128
Difference between static and dynamic linking?
Static linking: Linking of a library before a program is run. Dynamic linking: Delaying linking until program is run. Uses less space (can share libraries), reduced load time (not all libraries are needed every time the program runs). Allows plugins (dynamically-linked libraries with a standard interface). There are more, but these are examples. Must still use -L and -l (lowercase L) to make an executable that knows where to search for a particular dynamic library.
129
Shell commands in Makefile to make the directories as explained in class.
dirname/$(shell uname -s)-$(shell uname -m)
130
How to get exit code of the last process in Bash?
$? Is a special variable that gets the exit code of the last process
131
test expressions
test EXPRESSION where EXPRESSION is = strings match != strings don't match -eq integers are equal -ne integers are not equal -gt int1 greater than int2 -ge int1 greater than or equal to int2 -lt less than -le less than or equal to -e file exists -f file exists and is an ordinary file -d file exists and is a directory -a AND -o OR
132
How to test if something is a file?
-e FILE for if it exists -f FILE for if it exists and is an ordinary file -d FILE for if it exists and is a directory
133
Using test with control structures
if tests then stuff fi
134
What exit code does test use?
0 if expression is true. 1 if expression is false. Note that bash if and while statements check the return code and treat 0 as true and 1 as false*verify.
135
Difference between [ EXPRESSION ] and test EXPRESSION in bash.
They are synonymous. However, if you want to use AND and OR, you must use [[ ]] which uses && and || Note that there is also [[ ]] which
136
Bash wildcards.
* any character, 0 or more ? any character, just 1 [...] Any character in the brackets, 1 Causes bash to generate all matches. I.e. stat myfiles/* calls stat on every file in myfiles/
137
Pattern matching in bash
= in [[ ]] tests for pattern match, not just equality. [[ string = pattern ]] NOTE: pattern MUST appear on right side of the equal sign. i.e. abc = a* is true abc = a?c is true
138
Bash switch case
case teststring in pattern1) stuff ;; pattern2) stuff ;; esac
139
Bash while loop with inverted condition
until. loops until a test holds. i.e. until i=2 runs as long as i is not 2 until testcommand do stuff done
140
Bash, how can you use spaces in arithemetic expressions?
let "val=val * 10 + new" Enclose it in quotes
141
Bash for loop.
for (( expr1 ; expr2 ; expr3 )) do commands done expre1 is first evaluated expr2 is the condition expr3 is run whenever expr2 is true Recall int i=0; i<10; i++ from C
142
How to make an integer in bash?
You don't all variables are string, but interpretations of those change. Strings can also be interpreted as lists by separating them with newlines or spaces. Note that lists are different than arrays in bash.
143
Bash For ... in ...
for loopindex in list do commands done i.e. list="1 2 3 4 5" for i in $list do echo $i done or for i in a b c d e f
144
Bash, how to tell how many variables were passed.
$#
145
How to get all parameters passed as a list in bash?
$@
146
Bash, how to get the name of the calling program?
$0 i.e. ./abc $0 is ./abc i.e. /home/name/abc $0 is /home/name/abc
147
How to move positional parameters?
Using the shift command. $2 goes into $1, $3 goes into $2... Repeatedly using shift can be a convenient way to loop over all arguments that expect an arbitrary number of arguments
148
Bash, how can you execute many commands on the same line?
Separate with ; i.e. x ; y ; z
149
Bash control operators
&& and || && causes the shell to test the exit status of the preceding command. If exit code is 0 (indicating success) run the command, else skip it. || does the opposite. Runs if it fails.
150
Bash functions.
fname () { stuff } or function fname () { stuff } Arguments to a function become positional parameters within it. $# holds number of positional parameters $0 is unchanged when return is executed in a function, the function complete and execution continues after where the function was called. Note that you can give a numeric argument to return for an exit status
151
How do variables work with scope in Bash?
Normally shared, but can be declared local with the local builtin. local variables are only visible to the funciton and the commands it invokes they can shadow variables with the same name declared at previous scopes
152
How to declare an indexed array in bash?
declare -a name
153
How to declare an associative array in bash?
declare -A name
154
How to automatically create an array and assign a value in bash?
name[subscript]=value name=(value1,value2,...) automatically creates an array and assigns values
155
Bash, how to append to an array?
name+=(value1,value2,...)
156
How to reference an element of an array in Bash?
$(name[subscript]} gets an element $(name[@]} obtains the entire array as a list *verify
157
What does uniq do?
Detects repeated lines (they must be adjacent though, so consider using sort).
158
What does find do?
Searches for files in a directory hierarchy. -L to follow symbolic links, -H to follow links in arguments only find [-H|-L] path... [operand_expression...]
159
Command substitution.
'command' or $(command) but the slides say this one is rarely used. i.e. $(< file) does the same thing as cat
160
for ... in with text substitution
i.e. for i in @([a-z][0-9])
161
Arithmetic evaluation in BASH
(( )) is a synonym for let Can have spaces in the expression without needing double quotes.
162
How to evaluate many arithmetic expressions in one line? In bash
Using let, separate with spaces. Using (( )), separate with commas
163
Difference between malloc and calloc
malloc() allocates uninitialized memory calloc() does the same but initialized to all 0s calloc() example: void * calloc(size_t nmemb, size_t size); the block of memory has nmemb elements each that are size bytes long
164
How do void pointers work?
No type. Compiler doesn't associate one with it. Cannot be de-referenced with * since the data type it contains is unknown. Cannot do pointer arithmetic since that needs the C compiler to know the size of each element in bytes. Pointer comparison is still allowed. Must be cast into other types before use.
165
How to modify the value held beind a void pointer?
typecast *(int *) ptr) = 4;
166
What does the sizeof operator do?
Returns the size of the data element in bytes. Its arguments can be a variable an array name a basic data type the name of a derived data type an expression
167
What do you need to remember with malloc()/calloc()?
Always check the returned pointer. It may return NULL if it fails, in which case something very bad has happened. I.e. the system has run out of memory, or some other error.
168
How does free() know how much memory to free?
According to Stack Overflow. The specified amount of memory to allocate when using malloc() is more than what you give it. It includes extra information, including how big the block is. free() can look at this extra information.
169
What is a memory leak?
Memory that has been allocated by the programmer but never free()ed.
170
What is a wild pointer?
An uninitialized pointer.
171
What is a dangling pointer?
A pointer left pointing to a region of memory that has been free()ed.
172
What does realloc() do?
Lets you change the size of a previously allocated memory block (keeping the data). void * realloc(void *ptr, size_t size); Note: reallocarray() does the same, but better syntax for arrays. void * reallocarray(void *ptr, size_t nmemb, size_t size);
173
What happens when realloc called on NULL?
Acts like malloc.
174
Does realloc initialize data?
If the new size is greater, no.
175
How to move memory between locations?
memcpy() and memmove() void *memcpy(void *restrict dst, cont void *restrict src, size_t n); void *memmove(void (*dst, cont void *src, size_t len); memcpy does not work on overlapping regions memmove does work on overlapping regions Note that neither deallocate (free) the src. The memory there is still valid. Be vary careful when deallocating if regions overlap.
176
What are fast copies about?
When moving moving data around, it is fastest when able to move things in words and multiples of words. If it does not align, the compiler will determine the necessary bit shifts and masks to move it anyways. It can be faster to move bytes until it aligns and then use words until bytes are necessary again...
177
What can you do if you want to break at some point in a program with gdb but only if a condition is met?
break filename.c:linenum if condition_involving_vars
178
What does memset do?
void *memset(void *s, int c, size_t n);
179
How can you detect memory leaks?
valgrind
180
How can floating point variables overflow?
Overflow: values too large (towards +infinity or -infinity) Underflow: very tiny fractions (close to 0 from either positive or negative)
181
git how to make a new branch?
git branch newbranchname
182
git how to switch to a new branch?
git switch or git switch -c or git switch -c
183
git how to merge?
git merge
184
difference between git reset and git reset --hard
--hard erases your work too. just reset unstages changes
185
How to see the commit and other of each line of a file?
git blame or git praise
186
What files are opened when a process starts?
stdin stdout and stderr
187
When is a file created when you try to open it?
When you open it in write or append mode. If in read mode, and it doesn't exist, and error occurs. Note: Always check return values from system calls and library funcitons.
188
How to open a file?
FILE *someFile = fopen(const char *pathname, const char *mode);
189
fopen() modes.
r: read r+: read and write. w: truncate and write. w+: read and write. Creates file if it doesn't exist. a: appending. Created if file doens't exit. a+: reading and appending. File is created if it doesn't exist.
190
How to read and write from a file?
fprintf() and fscanf() do the same as printf() and scanf(), but take FILE* as the first argument. For entire lines of data, fputs() and fgets() fgets(buffer, n, filePtr); (1 less than n chars) fputs(buffer, filePtr); (note doesn't include null terminator by default)
191
How to redirect stderr in BASH?
command > outFile 2>errorFile Redirects stdout to outFile and stderr to errorFile command > outFile 2>&1 redirects stdout to outFile and stderr to stdout.
192
How to close a file?
fclose(inputFile);
193
When should you close a file?
Best practice is as soon as you are done with it.
194
How to tell if you have attempted to read pas the end of a file?
feof(filtePtr) returns non-zero if an attempt has been made to read past the file end
195
Low level file management. Opening a file.
Use open() int open(const char *pathname, int flags); int open(const char *pathname, int flags, mode_t mode); Returns -1 if an error occured. pathname and flags similar to fopens arguments. when a file is created, mode (access permissions) must be given Mandatory flags are one of O_RDONLY O_WRONLY O_RDWR Additionally, can use O_APPEND O_CREAT O_TRUNC can be combined with bitwise OR
196
Low level I/O, how to close a file?
close() int close(int fd); Returns non-zero if an error occured.
197
How to get a file descriptor from a FILE *?
fileno()
198
How to get a FILE * from a file descriptor?
fdopen()
199
How to get the error code for the last system call/library function?
errno() Can check it yourself or use perror() or strerror() to get a description of the error.
200
Low level I/O reading and writing.
ssize_t read(int fd, void *buf, size_t count); ssize_t write(int fd, const void *buf, size_t count); Let you read from and write to a file descriptor. Return value is number of bytes actually read/written (which may be less than requested).
201
How to change the file offset for a file descriptor?
lseek() off_t lseek(int fd, off_t offset, int whence); returns the associated file offset. whence: SEEK_SET: bytes from beginning of file SEEK_CUR: bytes from current position SEEK_END: bytes form end of the file
202
Benefits of OpenSSH?
Encrypts all traffic, including passwords, which can thwart attackers.
203
How can a simple awk program be ran?
Put in in quotes. i.e. awk '/h/' cars
204
What is the basic thing awk does?
Pattern matches like grep, but can make changes to the lines.
205
How to make a macro?
#define MACRO_NAME(arguments) (replacement) Remember to use parenthesis to prevent accidentally mixing in unexpected ways. I.e. passing x+1 to x * x gets 2x+1 when x^2+2x+1 is likely meant. i.e. #define SQUARE(x) ((x) * (x))
206
What does # do in front of a parameter in a macro definition?
Replaces the macro argument with a string constant. It literally just inserts double quotes around it. Note that it preserves other quotes and backslashes automatically.
207
Define statment, what does ## do?
Joins two tokens together.
208
Conditionals with #define statements?
I.e. #ifdef UNIX # define DATADIR "/some/path" #else # define DATADIR "\some\path" #endif
209
Conditional operator in C.
condition ? isTrueExpression : isFalseExpression
210
Register type qualifier
If a function makes heavy use of a variable, you can ask it to make it fast as possible by using register. i.e. register int index; register char *textPtr;
211
Volatile type qualifier
Like the opposite of const Says that the specified variable will change its value explicitly (which prevents it optimizing it out which can be useful for things like device I/O).