Midterm Flashcards

(108 cards)

1
Q

Hard vs soft link

A

a file is only removed if it has no hard links/name.

If softlink is deleted, only theirs iremoved. Any softlinks to a deleted hardlink is a dangling reference

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

Permission order

A

User Group Other

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

Permission to directories

A

read- you can only run ls
write- you can create or delete files
execute- you can go to subdirectories

If you have w permission to a directory you can delete the file itself

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

how to change permissons

A

chmod (letter of group user or other)+(rw or x) fname

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

uniq

A

remove repeats

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

head

A

first lines of provided input

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

tail

A

last lines of provided input

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

sed

A

a strem editor to perform text transformation

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

ps

A

view processes

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

forground job

A

has control of terminal

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

backroung job

A

runs concurrently with the shell in backround

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

fg [num] bg [num]

kill %num

A

moves to foreground, bg, and kill

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

job

A

gives list of jobs and each job number

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

> filen vs&raquo_space; filen vs < input

A

redirect, append, read from file

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

1 and 2 before >

A

stdout and stderr

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

*

A

zero+ chars

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

?

A

exactly one char

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

[x-y]

A

onechar x to y

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

[^oa]

A

not or or a

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

~

A

home`

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

~u

A

home directory of user

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

Scope

A

definind in script are lost in script unless used “source” to run script

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

parent and chil;d scop

A

child does not have access to parent shell unless with export

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

’’

A

literally

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
""
expand variables and do command subst, but nothing else
26
``
cmd substition
27
read fname lname
first is first word, last is everything else
28
set
set makes new positional parameters and throws out all of the items
29
command subst causes what
another process to be created
30
return value of a command
not output, 0 if success or other if failure
31
if statement
if return value is s0
32
test
is the same as []
33
while
loop until return value is 0
34
$@
same as $* except in quotes it does a quote for each larugment
35
$10
no work ${10}
36
char,int,long,float,double
8 32 64 32 64
37
address space
code, static data, dynamic data, and stack
38
what if you declare out of bounds
No will do something random
39
important mem
memory is allocated for the pointer, no mem is allocated to store waht the pointer points to
40
equivelent of pointer arithemtic
a[i] == *(a+i) | use indices, it uses the length of the data type
41
array paremeter
int sum(int *a, int size)
42
strings
are arrays of chars
43
can also do what to initialize a string
char[1] = "str":
44
string functions
#include
45
strncpy correct input
s1 s2, sizeof(s1)-1
46
contatenating a str
char *strncat(char *dest, const char *str, int n) takes up to n chars from src src has >= chars, it takes n chars and adds null byte
47
whats wrong with strcat
if src too long
48
*strrchr vs *strchr
extra r is reverse | these return pointers and NULL otherwise
49
functions in functions
will not have memory unless use malloc
50
what is malloc
malloc allocates /size/ bytes in the dunamic data segment. Returns the pointer to first byte or NULL if no space. Mmeory is uninitialized
51
free memory after done
free(var)
52
dangling pointers
if you free a pointer and then still use the pointer you can edit memory you dont own
53
malloc expectation
expects bytes so for ints you input * sizeof(int)
54
calloc(nmemb, size) and realloc(*ptr, size)
initializes zeroes to memory, changes size of ptr (alloc defined) to size bytes
55
* and &
* derefrences, & gets pointers
56
makefiles
target prereq reverse : reverse.c gcc -Wall -o reverse reverse.c afterwards: clean: rmbuxfer *.o
57
what happens in gcc
preprocessor runs and includes includes. runs.c files links them into an executable
58
errno
``` #include errno careful errno returns the last error number ```
59
perror
takes a *string
60
fprintf vs fputc
FILE *stream first vs second
61
file pointers vs descriptors
pipes and sockets vs regular files
62
how to open file
FILE *fopen (const char *filename, const char *mode)
63
reading
char *fgets (char *s, int size, FILE *stream);
64
Block I/O
fread and fwrite opperate on bytes
65
On success of fork
returns 0 to child, PID to parent
66
on failure of fork
returns -` to parent
67
wait()
pid_t wait (int *status). wait suspends until the children terminates
68
zombie
chold terminates but no parent is waiting. exit code is kept until parent collects through wait or parent terminates. shows up as z in ps
69
orpha
parent terminates before child orphans are adopted by init, PPID is 1
70
exec properties
Inherits PID and PPID, UID, GID | controlling terminal
71
exec()
execv( char *path, charargv[])
72
shell commands
shell forks then execed the typed command
73
begin and end a for and if statment
do done if fi
74
evaluate file dir and or exists or
-f -d -a -o -e
75
begining of shell
#!/bin/sh
76
access current path
$PATH ~ $#
77
access home
~
78
cp [dest]
works being in a for loop
79
``` System calls • Files • Processes (fork, exec) • Inter - process Communication – signals – pipes – sockets – select ```
``` ob control • Pipes read expr ```
80
Compiler vs. Interpreter
``` ompiler translates whole program to object code. – produces the most highly optimized code • Interpreter translates one line of code at a time. – can quickly make changes and try things out • C – compiled • Java – compiled to byte code, then interpreted. • Shell – interprete ```
81
how does fork work
createa child process and a duplicate of the current one both run concurrently and independantly
82
child returns what
fork returns 0 to child fork returns c PID to parent or -1 if failure
83
how to instatniate pid
pid_t pid; | pid = fork();
84
when does a child end
like any other program | when exit or func return or when a sig makes it terminate
85
exit status of most recent command is
$
86
why use wait?
child to complete exit occde of a child
87
what does it do and how to use
wait until one child terminates - block if all children run return PID of terminated child return -1 if no children
88
what is statustatus
exit status WIFEXITED(status_NO_var) if normal exit WEXITSTATUS gives exit status
89
zombie child
terminates but parents are not wiaiting the exit code is a zombie until parent colects it exit code is z in ps
90
orphan child | they go where
parent terminates before child orphans get adopted by init initi is the first process started init has pid of 1 the ppid of orphans is 1
91
waitpid
wait for a specific child waitpid( pid, int *status, int options) options is 0 it blocks just like wait if options is WNOHANG it immediantly returns 0 instead of blocking when no child
92
exec
replaces the program run with a different run stats frombeggining exec returns -1 on failure never does on scuess
93
execl execv exec lp exec vp
exec list vs exec array eveclp doesnt need path
94
fd preservation
across forks and execs
95
job control
use ps to view processs forground is contorl of termnal backround concurrently with sjhell and in backroiund jobs give u a lit with nm fg and bg puts it in the place kill %num kills the job
96
pipes
are one way coms managed by os ll file ds
97
opten r w c
open (const char *path, flags) returns fd flags as O_REDONLY O_WRONLY or ORDWR read (int fd, void *buf, size_t count); returns bytes, 0 for eof and -1 for errors int close (fd)
98
std streams
0 input 1 output 2 error as automatic fds | ead
99
pipe create
int pipd(int pidefd[2]);
100
read does what
blocks until data is avaliable writing is closed read0 detects eof and returns pipes close when process ends make sure to do what with parent close parents writing end
101
do waht before using
before readding close p1 | before writing close [0
102
what if you fail
try to write a pipe without reading SIGPIPE will ter If you write and buffer is full write blocks until space frees up read and noby has a writing end read returns EOF read a pipe and there is no data read blocks
103
how to connect stdout to sdin
return code = dup(oldFD, newFD); new and old now refer to the same newFD isopen it closed returns to FDs not streams
104
all signals
``` SIGTERM, SIGABRT, SIGKILL – SIGSEGV, SIGBUS – SIGSTOP, SIGCONT – SIGCHLD – SIGPIPE – SIGUSR1, SIGUSR2 ```
105
how to use signal
signal(SIGNALNAME, function); can put in SIG_ IGN for fcn SIG_DFL
106
sigaction
struct sigaction newact newact.sa_handler = ?; newact.sa_flags = 0 if recieve SIGINT, &newact, oldaction)
107
sa_mask
block while one handler is running blocked signals dont run until unblocked ``` int sigemptyset(sigset_t *set); int sigfillset(sigset_t *set); int sigaddset(sigset_t *set, int signo); int sigdelset(sigset_t *set, int signo); int sigismember(const sigset_t *set, int signo); ```
108
bitwise
``` <<2 moves all bytes 2 to end bits fall off ~ not & and ^ xor l or ```