1/38
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
How to write c style bash function called foo
foo(){
return 1
}
How to write c bash function called foo
foo(){
echo 1
}
What does shift do in bash?
Shifts the $@ to the left ($2 becomes $1 and so on)
What is the scope of variables in bash?
All variables are totally global unless defined as local than it is local to the scope of function it was created in
In c how do you format printing?
%s : string
%d : decimal
%f : float
%lf : long float
%c : char
%5d : width of 5 right justified
%-5d : width of 5 left justified
%5.2 : width 5, precision of 2
What are the different types of FILE *?
stdin
stdout
stderr
What are the standard file descriptors?
0 : std in
1 : std out
2 : std error
How to open a file with stdio, what happens if it fails
fopen("foo.txt", "r") returns NULL if it does not open and sets errno
What are the flags with opening a file with system call interfaces?
O_RDONLY : read only
O_WRONLY : write only
O_RDWR : read/write
O_APPEND : opens and at EOF
How to open a file with system call interfaces, what happens if it fails
fd = open("foo.txt", O_RONLY)
Returns a file descriptor of -1 if fails.
how to read/write from a file with stdio?
FILE* fp = opens file pointer
char ch;
fscanf(fp, "%c", &ch);
fprintf(fp, &ch);
how to read from a file with system call interfaces?
int fd = opens file descriptor
char ch
read(fd, &ch, 1); => returns size of what was read
write(fd, &ch, 1);
What is the return of c call stat?
0 if success -1 if error
how to create a bit field?
struct foo{
char x : 3;
char y : 5;
}
What is the return of getopt and how can it be used?
char opt;
while ( (opt = getopt(argc, argv, "abcd")) != -1){
switch(opt){
case 'a' : ....
case '?' : => case if option is not found
}
}
what is the return of getopt if the option is not found?
ascii number of '?' i.e. 63
Make a Make file with macros for project with objects main, a, b with a default and cleat target.
CFLAGS = -std=gnu89 -Pedantic -Werror
OBJECTS = main.o a.o b.o
mainTarget: $(OBJECTS)
gcc $(CFLAGS) -o mainTarget $(OBJECTS)
CLEAN:
-rm $(OBJECTS) mainTarget
main.o : main.c a.h b.h
a.o: a.c a.h
b.o: b.c b.h
How to make a flag in getopt have a required argument and how do you access that argument?
"a:" => makes the -a flag required to have argument
To get the arg call the "optarg"
What does c fork() return?
returns the pid, and if it is inside the kid process it will be 0, -1 means it failed to fork
What does wait() do, and how to wait for ALL child processes
Pauses the process and resumes when child terminates. Parent gets the child exit status,
while(wait(NULL) > 0);
unformatted
read and leaves it as it was given
formatted
read and changed into an actual # value
formatted examples
«, », printf()
unformatted examples
get, put, read, write, getline
library calls (stdio)
buffered
system calls
not buffered
what does “clean” do
removes object files. Gets rid of all .o files
write bash function that outputs all subdirectories in current directory
for dirs in $(ls)
do
if [[ -d $dirs]]
then
echo $dirs
fi
done
fragment of code that uses a for loop to display all parameters passed to script
for var in $@
do
echo $var
done
fragment of code that uses a while loop to display all parameters passed to script
while [[$1]]
do
echo $1
shift
done
linux library
.so
env variable allows executable to be executed without user providing absolute path
PATH
regex exp that starts with any number (multiple digits followed by colon)
^[0-9]+:
1 liner to copy a file where path to file is specified in file named dirs to current directory. dirs is in current directory
cp $(cat dirs)./
abandon all changes in vim and quit
:q!
argc
number of arguments
what is a race condition
bug where outcome of a program is determined by which thread or process finishes first
what is blocking
waiting until it receives
what is a zombie
child process in which a parent has not called wait() on. Process cannot end until someone takes its exit status