CSI 3336 Final - Aars

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall with Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/363

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No study sessions yet.

364 Terms

1
New cards

gdb - steps through program one step at a time

n (next)

2
New cards

A product that can be used to determine and find memory leaks

Valgrind

3
New cards

Create and maintain static libraries

ar (archive)

4
New cards

A single copy of a library loaded into memory

Shared libraries

5
New cards

First call to open returns

3

6
New cards

File descriptor

fd

7
New cards

Function that returns a different value every second

time()

8
New cards

Libraries in Linux are known as archives. What is the typical file extension?

.a

9
New cards

Create directory named 'cs3336' (located back one directory in myClass)

mkdir ../myClasses/cs3336

10
New cards

Print all files named fooxx (f case insensitive, xx - two base 10 digits) to printer ecs312

lpr -P ecs312 [Ff]oo[0-9][0-9]

11
New cards

Find the max value using a bash shell script

#!/bin/bash

maxValue() {

max=$1

shift

for val in "$@"

do

if [[ $val -gt $max ]]; then

max=$val

fi

done

echo $max

}

result=$(maxValue 15 18 32 4 98 1)

echo "Max is: $result"

12
New cards

Write a makefile for project (myprog)

- Must have ability to clean, use at least 1 macro, force gnu89 standard on all compiles

CC = gcc -std=gnu89

OBJ = main.o a.o b.o

myprog: $(OBJ)

$(CC) -o myprog $(OBJ)

main.o: main.c a.h b.h

$(CC) -c main.c

a.o: a.c a.h b.h

$(CC) -c a.c

b.o: b.c b.h

$(CC) -c b.c

clean:

rm -f myprog $(OBJ)

13
New cards

What is a system call?

Fundamental interface between an application and the Linux kernel.

14
New cards

How is a system call similar/different from other functions?

Other functions (wrapper functions) invoke system calls. System calls perform the same functions as library functions, but at a different layer of abstraction.

15
New cards

When would you choose to use a system call versus another function?

When working with file descriptors and pipes, system calls must be used to read and write.

16
New cards

Using only system calls for I/O, write readADigit()

- reads individual digit, give int back to calling function if it exists

#include

int readADigit(int fd) {

char ch;

int result = -1;

if (read(fd, &ch, 1) == 1) {

if (ch >= '0' && ch <= '9') {

result = ch - '0';

}

}

return result;

}

17
New cards

Code fragment that uses getopt() to count number of v options given on command land and prints count

-v option: get increasingly verbose diagnostic output

#include

#include

int main(int argc, char *argv[]) {

int opt;

int vcount = 0;

while ((opt = getopt(argc, argv, "v")) != -1) {

if (opt == 'v') {

vcount++;

}

}

printf("Number of -v options: %d\n", vcount);

return 0;

}

18
New cards

Calls the command pwd and redirect its stderr to a file named errLog

pwd 2> errLog

19
New cards

Variable expansion but not file name expansion

" "

20
New cards

The (1) symbol will be expanded as the path to your current directory.

.

21
New cards

Old internet standard protocol for a remote terminal connection

Telnet (23)

22
New cards

Secure alternate protocol

ssh (22), encrypts communication between server and client

23
New cards

Print the number of lines that the string "Bear" is found in the file pressRelease

grep -c "Bear" pressRelease

24
New cards

Replace all occurrences of "Dwayne Johnson" in a file named pressRelease with "The Rock"

sed 's/Dwayne Johnson/The Rock/g' pressRelease

25
New cards

Vim: moves cursor to beginning of file

gg

26
New cards

Vim: get editor to save copy of current file

:w

27
New cards

Vim: get editor to move cursor to end of current line

$

28
New cards

Regex that matches: catinthehat.txt

grep -E "catinthehat.txt" file_name

29
New cards

Regex that matches bears (first letter case insensitive)

grep -E "[Bb]ears" file_name

30
New cards

Shell Expansions: "file" followed by any single char followed by ".txt"

file?.txt

31
New cards

Shell Expansions: all files located in user SMITHB's home directory ending in ".sh"

~SMITHB/*.sh

32
New cards

Shell Expansions: files named "foo" with the first character case insensitive

[Ff]oo

33
New cards

Write to a stream (overwrite)

>

34
New cards

Write to a stream (append)

>>

35
New cards

Developers of C

Denis Ritchie, Brian Kernighan

36
New cards

KISS Principle

Keep it Small and Simple

37
New cards

Good for quick and simple development

shell

38
New cards

C shell

csh

39
New cards

Bash spawns new shell, executes given command, then returns result. (T/F)

True

40
New cards

Bash built-ins run on the original bash, and as a result, is faster and more efficient. (T/F)

True

41
New cards

Do not suppress variable expansion. Suppress shell expansion.

" "

42
New cards

Suppress everything

' '

43
New cards

``Command substitution

- Identical to $(_)

``

44
New cards

Standard in

0

45
New cards

Standard out

1

46
New cards

Standard error

2

47
New cards

Universal trash can in Linux

/dev/null

48
New cards

kills precess specified by pid

kill

49
New cards

grabs all processes related to a specified user

ps -ef | grep user_name

50
New cards

returns first 10 lines

head

51
New cards

returns first num lines

head -num

52
New cards

returns last 10 lines

tail

53
New cards

returns last num lines

tail -num

54
New cards

takes stdout for the first process and uses it as stdin for another process

pipe

55
New cards

allows every instance of the shell to have access to the variable

export

56
New cards

In Bash, 0 is considered true (T/F)

True

57
New cards

global regular expression print

grep

58
New cards

special command (substitution in ed)

- manipulates strings, but by default, does not modify files

sed

59
New cards

Remove all instances of 'TX', replace with Texas

sed 's/TX/Texas/g' file_name

60
New cards

change in place

sed: i

61
New cards

character class

[...] (file name expansion)

62
New cards

range of a number of occurrences (at least n, at most m)

{n, m}

63
New cards

exactly n occurrences

{n}

64
New cards

at least n occurences

{n, }

65
New cards

at most m occurrences

{ ,m}

66
New cards

or

|

67
New cards

escape

\

68
New cards

Shebang line

#!/usr/bin/bash

- indicates what interprets the file

69
New cards

Read, write, executable permissions

- 3 sets of octal numbers

- chmod

-rwxrwxrwx

70
New cards

You must give file executable permissions OR (1)

1. explicitly give it bash when executing

ex. $bash ./hw.sh

71
New cards

Substrings in bash

echo ${foo: starting point: num of char}

72
New cards

Use $(( )) for simple arithmetic and let for unary operations. (T/F)

True

73
New cards

Test

[ ]

[[ ]]

74
New cards

String comparisons

= equivalence

!= not equal

-n not null

-z is null

75
New cards

Number comparison

-eq

-ne

-lt

-gt

-le

-ge

76
New cards

File tests

-d: is a directory

-e: does it exist

-f: regular file

77
New cards

if

if [[ test ]]

then

# stuff

fi

78
New cards

if-elif-else

if [[ test ]]

then

# stuff

elif [[ test ]]

then

# stuff

else

#stuff

fi

79
New cards

case

case val in

pattern1)

# stuff

;;

pattern2)

# stuff

;;

pattern3)

# stuff

;;

esac

80
New cards

for

for var in $set

do

# stuff

done

81
New cards

while

while condition

do

body

done

82
New cards

shifts all items in command line/positional parameters

- allows for reuse of $1

shift

83
New cards

until

until condition

do

body

done

84
New cards

shell suppression

../

85
New cards

Functions in bash

function()

{

body

}

86
New cards

Returning from a function (bash)

1. use of return command (returns an integer, stored in $?)

2. returning as we know it (using echo)

87
New cards

C is a (1) of C++

1. subset

88
New cards

Compile in gnu89 standard

gcc -std=gnu89 file_name -o executable_name

89
New cards

Analogous to new and delete

malloc and free

90
New cards

variables which hold addresses

pointers

91
New cards

printf

%i - integer

%d - decimal

%c - character

%s - string

%f - float

%g - double

%lf - long float

%5d - set width of 5, double, right justified

%-5d - set width of 5, double, left justified

%05d - zeroes leading number

%8.2f - 8 columns, 2 decimals

92
New cards

Interfacing directly with OS via System Call

1. Process control

2. File management

3. Device management

4. Information management

5. Communication

93
New cards

Electric fence

If memory is used incorrectly, segmentation fault

94
New cards

User Space

User Applications, GNU C libraries, Shell

95
New cards

Kernel Space

System calls interface -> device drivers

96
New cards

Hardware Space

Hardware

97
New cards

System-wide error variable

Errno

98
New cards

read()

read(int, void *buffer, size)

99
New cards

write()

write(int, void* buffer, size)

100
New cards

open()

open(char *name, int flags)