prepare for interview Flashcards
Hard Disk
Non-volatile data-storage device. rotating magnetic disk.
Uses magnetic storage to store and retrieve digital information. composed of one or more rapidly rotating platters coated in thin magnetic material. Data accessed in random-access manner (can be stored and retrieved in any order).
Non-volatile: retain stored data when powered off.
Computing Machine
Machine that does something based on input, and produces output
Turing Machine
‘the blueprint of modern computing’. ‘Machine’ that recieves a tape of 1’s and 0’s, reads it, changes 1’s to 0’s and 0’s to 1’s according to instructions. the tape that used to be a question becomes an answer to the question.
Initially just a theoretical idea of a device that, when given a tape of whatever needed length of 1s and 0s, reads the tape and changes the 1s and 0s in accordance with its instructions. the tape of 1s and 0s starts as a question, and when the turing machine is finished with it, becomes the answer.
Von-Neumann Architechture
computer model designed by John Von-Neumann in 1945.
Input -> Memory -> Output
V> Processor (Control Unit <->Arithmetic Logic Unit)
+ Input stored as command in Memory,
+ Processor fetches command from Memory,
+ CU manages commands and input/output,
+ ALU handles calculations,
+ CU stores complete commands in memory,
+ Output is displayed.
Operating System
Program that allows a user to interact with the computer.
History of Linux
developed by Linus Torvalds.
started in 1991 as a pet project,
became community open source project
Linux 1.0.0 launched in 1994
What is Linux?
Open source Operating System. Android is based in Linux.
CPU
Central Processing Unit. interprets and executes all instructions. consists of single microprocessor, but stronger mainframes use one or more. contains CU and ALU (Command Unit, Arithmetic Logic Unit)
- CPU cache
Stores temporary files.
Small chunk of memory on the computer’s processor that stores basic computer instructions that were recently or are frequently used.
Makes processing go faster because frequent data close to CPU
RAM
Computer memory that can be read and changed in any order.
Typically used to store working data and machine code.
ROM?
EPROM?
Read-Only Memory. Non-volatile memory, cannot be electronically modified after manufactury.
Erasable Programmable, read only memory. can be erased if exposed to certain ultraviolets.
BIOS
Basic Input Output System
Boot Loader
Computer instructions in ROM in motherboard chip.
Controls input and output operations.
Loaded into memory on startup, performs POST (power on self test), then loads OS from hard drive into memory.
BUS (Address, Data, Control)
Set of wires carrying signals between devices. connect CPU, memory and I/O devices.
Address bus: carries the address of memory location/ IO device CPU is communicating with
Data bus: carries data between CPU and memory / IO device
Control Bus: carries control signals, telling IO devices what to do
I/O device
Any external device that could send input or receive output.
(secondary storage, keyboard, mouse, monitors, printers)
File system
The way in which files are named and placed logically for storage and retrieval.
NTFS, NFS and ext4 are file systems.
Program
Set of code and instructions meant to complete a task.
Process
Running instance of a program
USB
Universal Serial Bus
Technology that connects computers with external devices
Serial Port
Connector that sends data one bit at a time.
May be connected to a computer.
Parallel port
Device Connector,
sends/receives several bits of data simultaneously using more than one wire.
RS-232
slow but reliable standard transferring data as voltage signal. relatively slow, used still for modems, printers, and other peripherals.
(U)EFI
Unified Extensible Firmware Interface.
Boot Loader, Replacement for BIOS, controls startup process. supports larger hard drives, faster boot times, improved security, adds GUI to configure UEFI settings.
Boot Loader
Loads an operating system when a computer is turned on. Stored in non-volatile memory (ROM)
GRUB/LILO
GRUB: new boot loader with multi-OS device management. Supports Windows, Linux, UNIX, macOS, BSD, and Solaris.
LILO: older boot loader with single OS device management. Only supports Linux.
ATAPI
Advanced Technology Attachment Packet Interface
Extension for ATA(/IDE) standard, allows non-hard drive devices to connect to computer (CD-OMs, DVDs, Blu-ray).
Uses command-based protocol allowing host computer to send commands to the device and receive data from it.
SATA
Serial Advanced Technology Attatchment
Replaces older PATA (Parallel) standard, used for hard drives, SSD’s and optical drives.
(remember ATAPI)
Master Boot Record
Boot sector at beginning of storage device (holds partition table + bootstrap code)
Locates OS, loads it to memory, transfers control to OS.
MTBF
Mean Time Between Failiures.
Average time between breakdowns, used to measure performance/safety
Swap File
System file that creates temp storage on SSD/HD when system low on memory.
Swaps section from RAM storage from idle program to be used by other programs.
Simulates disk space as RAM.
Virtual Memory
OS technique using hardware and software to temporarily transfer data from RAM to disk storage.
Compensates for physical memory shortage.
Inode
File data structure, stores metadata about a Linux file (except name and data)
Keeps track of all files in Linux System.
ASCII table
America Standard Code for Information Interchange: assigns numeric IDs to each letter, numeral, punctuation and other characters.
Subset of Unicode, developed in 1960’s
Unicode
Worldwide encoding standard.
developed in 1980’s to support a total of 65,536 characters (including ASCII) and more from other languages and scripts.
Unicode characters take variable length characters, and therefore take more space than ASCII.
wchar
Wide Character.
Size of wchar is implementation-defined, but typically 16 bits.
wchar_t *wide_string = L”Hello, world!”;
UTF-7/8
7-bit / 8-bit encoded Unicode Transformation Format.
7 is backwards compatible, still used in emails. 8 is more efficient and supports more characters, used for web and other applications.
POSIX
Portable Operating System Interface
set of OS interface standards based on Unix. Any two software conforming to POSIX standard should be compatible.
GNU
GNU’s Not Unix
Unix-like OS; Collection of programs (applications, libraries, developer tools, and games)
Started by Richard Stallman in 1983, as the GNU Project.
goal: create a free OS that is compatible with Unix.
relevent components:
GNU Compiler Collecction (GCC),
GNU Debuger (GDB)
GNU C Library (glibc),
Bourne Again SHell (bash)
And of course others
IP / TCP / UDP
Internet Protocol, responsible for routing data backets between computers
Transmission Control Protocol: does the TCP handshake and ensures all packets reach their destination
User Datagram Protocol: connection-less protocol, which does not guarantee data is delivered reliably or in the right order.
Kernel
Core of the OS. All system calls from User Space communicate with the Kernel.
System Call
routine that allows user apps to request actions that require special privelages (create, delete, open, close, read, write)
Waterfall
Project Framework that breaks down of project activities into linear sequential phases
SCRUM
Project Framework that starts with what can be seen/known. then tracks progress and tweak as necessary.
Emphasizes teamwork, accountability and iterative progress.
Is an example of Agile Development
Agile Development
Project Framework for iterative and incremental development.
+ rapid, flexible responses to change.
+ customer collaboration over contract negotiation
+ responding to change over following a plan
+ working software over comprehensive documentation
Scrum and Extreme Programming are forms of Agile Development
NTFS
New Technology File System
Used by Windows NT for storing/organizing/finding files on a hard disk. Direct upgrade to FAT16/32.
Reliable: Is a Journaling file system (keeps track of file changes in journal for recovery)
Efficient: features file compression and sparse files
Secure: supports Access Control Lists (ACLs) to control file access.
Encryption: supports file encryption to be accessed by authorized users.
Default file system for windows NT, 2000, all the way up to windows 10.
Also supported by Linux and macOS, but those primarily work with ext4.
NFS
Network File System
Protocol for storing files on a network. Distributed file system for accessing files/directories on remote computers and treat them as if they were local.
Scaleable (can add more users/devices)
Reliable (withstands network failiures)
Efficient (uses network resources as opposed to shoving more physical memory into a machine)
FAT-16/32
File Allocation Table
FAT16, introduced in 1977, for Floppy disks. stores file/folder info as 16-bit entries. max size of FAT-16 partition is 2GB
FAT32, introduced in 1996, for USB flash drives and SD cards. stores file/folder info as 32-bit entries. max size of a FAT-32 partition is 32TB.
JFS
Journal File System, created by IBM.
Meaning the file system tracks changes to files and folders in a log file, to backtrack changes in case of system crash or power failure. ext4 is a JFS.
ext4
Fourth Extended File System (after ext1, ext2 and ext3)
Journal file system (JFS) for Linux. higher supported size (1 exabyte).
Primary Disk Partition
first part of MBR partitioned hard drive.
stores OS, boot files (that start the computer)
Extended Partition
Partition that holds multiple logical partitions.
Logical Partition
Partitions that hold data and applications. (Data files, Media files, Applications, Backups, Games, Software)
What are the 9 sections of the manual? (man command)
1 General Commands
2 System Calls (provided by kernel)
3 Library Functions (from program libraries)
4 Special Files (usually to do with /dev/)
5 file formats and conventions (usually to do with /etc/)
6 games: oops
7: Miscellaneous: Macro Packages and Conventions, boot parameters,
8: Sys-admin commands: usually reserved for root
9: Kernel Routines: info about internal kernal operations
which command tells you which manual section the “write” command is in?
man -f write // returns page/section write is in
When there is more than one program with the same name in the file system, how do you know which will run?
1: program in the same directory will run first,
2: else, the OS will look for the first program that appears in the $PATH environment variable,
3: if it doesn’t exist, OS returns an error.
what do the “which” and “type” commands do?
which returns the path to the executable, and type returns information, like if the command is internal/external
which ls
returns: /bin/ls
type ls
returns: ls is a shell builtin
write an alias to remove files ending with ~ from the current directory
alias rt~=’rm -r *~’
In which file would you place an alias so that you have it when you start a new bash?
~/.bashrc
Create a shell function that checks if a file exists. if it does, then copy it to /tmp
!/bin/sh
FILE=1
echo “please enter file name.”
read FILE
if test -f “$FILE”; then
cp “$FILE” tmp/”$FILE”
fi
login to another computer and run gedit on a file in /tmp. ensure that the window that opens is on your computer, and not the remote computer
ssh username@host_ip_addres
cd /tmp
touch whatever.txt
gedit whatever.txt
What is the command for knowing who is logged in?
who -b
What is the command for checking last reboot?
last reboot
What is the command to confirm your IP address?
ifconfig
What are the commands you can use to see computer resource usage?
top
htop (for better view)
nmon
gnome-system-monitor
What is the command for setting your computer’s clock?
sudo timedatectl set-time hh:mm:ss
Write a shell script that records the current time to a file in /tmp
!/bin/sh
touch “/tmp/date.txt”;
echo $(date)»_space; “/tmp/date.txt”;
Command to know how long it takes for -ls -m to run?
time -ls -m
What are the differences between crontab, at and batch?
Cron: runs tasks at regular intervals (once a minute, once a day…) think backups and notifications
crontab -e
0 2 * * * echo howdy //echoes at 2am every day
At: runs task at a later time (think running a test suite or compiling code)
at now +5 minutes
> notify-send “commit to bathroom”
> CTRL+d
Batch: just calls at, to run in the background.
command to know what processes are running on the machine?
ps aux
command to know PID of shell environment?
echo $$
ls command, but display hidden files?
ls -a
ln VS ln-s
Hard Link: Creates a file sharing the same inode. Good as backup, files are deleted when their last hard-linked pointer is deleted.
Soft Link: creates a file pointing to the other file’s location. soft link can point to files in other file systems.
think about pushd popd
take your time.
Why are the -i, -r and -f flags for cp, mv and rm?
why doesn’t mv have -r?
-i interactive (prompts “are you sure you want to delete/overwrite?”)
-f force (if it cannot be opened, delete and try again)
-r recursive (take into account all subfiles/subdirectories)
mv works with recursive flag by default.
command to check used disk space?
df,
or df -h for human
command to edit file permissions
remove write and execute from group and others.
give read write execute to user.
set owner of the file to “guests” group
chmod go-wx file.txt
chmod u+rwe file.txt
sudo chgrp g-rwx file.txt
command to add a guest account with guest password to machine
create a guests group,
add guest to guests group
useradd guest
passwd guest 12345
groupadd guests
usermod -a-G guests guest
count the number of words that start with ‘a’ and end with ‘z’ in the dictionary file, and print the number to a file in /tmp
grep -c “^a.*z$” /usr/share/dict/words
Display the words in a file containing qui respelled with kwi
grep -E “qui|kwi” file.txt
in a command: what are the last 20 words in the dictionary?
tail -20 /usr/share/dict/words
What is the difference between a swap file and a swap partition?
swap file handling is more flexible, but slower. (can’t enlarge a swap partition without disk management tools)
Swap partitions are faster, and more common.
What is Bash?
Bourne Again Shell.
command language interpreter, executes commands read from .sh file.
Global Variable in Bash
variable declared outside of any function or loop, and can be accessible from anywhere in the script.
printenv (bash)
prints environment variables
What is the meaning of #!/bin/bash
“shabang”.
inscructs the program loader to use the /bin/sh program instead of any other, passing the path of the script as the first argument.
How do you make multiline comments in bash?
: ‘
will not execute
‘
What is Version Control?
AKA source control, the practice of tracking and managing changes to software-code.
version control tools help software teams manage changes to source code over time.
Git is a Version Control Tool
Define Git
Distributed Version control system
What is a Git repository?
collection of files and folders that are tracked by Git
What is the Git HEAD?
Pointer to the current commit.
git checkout makes the HEAD point to a different branch.
git commit sets the head file to point to the current commit.
What is the Git Staging Area?
files to be handled by the next commit.
git add adds files to the staging area
What is the difference between git fetch and git pull?
fetch downloads changes to local repository,
git pull calls fetch AND merges them into your local branch.
What is the difference between the HEAD and the master?
HEAD is a file located in the .git directory. contains pointer to current commit.
Master is a branch in the git repository. a branch is a pointer to a specific commit.
What is the difference between git reset –hard and git reset –soft?
soft reset: moves HEAD to the specified commit, and un-stages files added to staging area between current state and specified commit.
hard reset: destroys all changes and removes them from the working directory, staging area and commit history.
(soft reset un-adds changes. hard reset deletes changes.)
What is a sequence point?
a point in the code where previous expressions have to resolve before proceeding.
examples: && || , ;
function calls, return, the conditional expressions of if/while/do…
C escape character for newline
\n
what defines an expression as having an l-value, and what is a side effect?
expressions with l-value have a persistent (FINDABLE) location/address in memory.
(a = 7; /you can find the address of &a/)
(10 += 7; /* you can’t find the address &10 */)
What is the difference between a declaration and a definition?
Declaration tells the compiler about the existence of a variable/function/object.
int x; void function();
definition tells the compiler the location and size of a variable/function/object.
int x = 10; void function() { return 10; }
What is the difference between unspecified and undefined behavior?
Unspecified: undefined by programming language standard
Undefined: undefined by programming language standard AND will cause unpredictable program behaviour
What is the difference between unspecified and undefined behavior?
Unspecified: undefined by programming language standard
- function arguments can be evaluated in different orders,
- pointers pointing to uninitialized memory
Undefined: undefined by programming language standard AND will cause unpredictable program behavior
- accessing array element out of bounds
- dividing by zero
- de-referencing null pointer
what defines Data, Stack and Heap variables?
Data variable: allocated in data segment, initialized when program starts, de-allocated when program ends. int x = 10;
Stack Variable: allocated in stack segment, initialized when function is called, de-allocated when function returns (most anything inside functions)
Heap Variable: allocated in heap segment (for dynamically allocated memory), initialized when allocated, de-allocated when freed. (malloc, calloc, free)
What is an array?
collection of variables of the same type
double balance[3] = {1.2, 3.4, 5.6}
What is Forward Declaration?
declaring a variable before providing a definition.
int func();
//code
int funct(){ return 7;}
what does assert do in C?
include <assert.h></assert.h>
void assert(int expression);
prints message to stderr and aborts the program if false or 0.
“Assertion failed: expression, file filename, line line-number.”
What will happen if you use a dangling pointer?
segmentation fault (please use free)
in debugging, what is breakpoint, watchpoint and catchpoint?
breakpoint: stop executing at break line
watchpoint: stop executing when target memory location is modified
catchpoint: stop executing when a specific event occurs
What is a memory leak?
program error, allocated memory isn’t freed.
What is Word?
the size of the basic unit of data that a computer processor can manipulate.
depending on the computer architecture, this is either 32 or 64 bits, typically represented as an “int” by 32-bit or 64-bit computer.
argc, argv and envp?
argc: variable, stores number of arguments passed to C program
argv: array, stores arguments passed to the C program
envp: pointer to array of pointers to environment variables
(environment variables being HOME, PATH, LANG, LC_ALL, USER, USERNAME, and more)
given x = “toot”,
difference between sizeof(“x”) and strlen(“x”)?
sizeof will give the size in bytes (4 characters, 4 * 1 bytes)
strlen will return the length, including the escape character \0 (5)
what are stdin, stdout and stderr?
Standard Input/Output/Error Streams; interconnected I/O channels between a computer program and its environment during runtime.
stdin recieves text as input.
stdout outputs text to the shell environment
stderr outputs error messages
enum
Special type representing a group of constants
enum Level {
LOW,
MEDIUM,
HIGH
};
enum Level some_level;
some_level = LOW;
some_level = HIGH;
struct
Groups related variables of varying types.
chain of responsibility
Behavioral design pattern of passing requests down a chain of handlers. Each handler either processes the request or passes it to the next handler.
what is a file, in linux?
A named collection of data on a storage device. can be text, images, programs, etc.
All files are organized under a file system.
what is the difference between fopen() and open()?
what is the difference between what they return?
fopen() and open() are functions in C used to open files.
fopen() is a library function (implemented by C standard library). Returns a pointer to a FILE object. Has a variety of modes (“r” reading, “w” writing and “a” appending, and others).
open() is a system call (implemented by the OS). Returns an integer file descriptor (identifies the file on the OS)
Header File
include header_file_name.h
.h file with declcarations and macro definissions to be shared between source (.c) files.
Header Guard
ifndef FILENAME.H
#define FILENAME.H
code in header file to prevent duplicate implementation of the same code.
Preprocessor
Macro processor, transforms .C into .i file, removes comments, runs macros
(header file inclusion, macro expansion, conditional compilation, line control [inform line’s origin file])
Linker
links .O files together into single binary executeable.
resolves symbols,
assigns load addresses for object files.
Compiler
transforms source code into machine (byte) code.
stack, heap, bss, initialized data segment, text segment
stack: memory for local variables/function arguments, return address of current function. managed by compiler.
heap: memory region for dynamically allocated variables (not known at compile time, malloc, calloc, realloc, free)
bss: (blank started by symbol) memory region initialized to 0. store uninitialized global/static variables. managed by OS
initialized data segment: memory region for initialized data (global/static variables) known at compile time.
text segment: read-only memory region for machine code and constants (size of the stack or heap)
Static
function/variable restricted to same file it is defined in.
funcs are global by default.
Interface VS implementation
Interface: Blueprint portraying how a function should be implemented later.
Implementation Software “around” the interface/blueprint. defining the function’s implementation.
API
Application Programming Interface.
code that enables two software programs to communicate
Shell commands:
What do ar, nm and objdump do?
ar: create, modife, extract archives (file holding other files called “members of an archive”)
nm: list symbols from object files.
objdump: display information from object files.
Software Build process from c sources to running program:
- preprocessor strips .c file into commentless .i (preprocessed) file, runs macros
-compiler converts .i code into assembly .s file.
-linker performs symbol resolution, relocation, links object files together into single relocateable file.
- locater takes relocateable file and linker script file, converts into executeably binary image.
What does extern do in C?
Declares variable to be linked externally
Recreate the Bursa program
void Bursa(int arr[], int size, int* bursa_arr)
{
int test_buy_i = 0;
int test_sell_i = 0;
int i;
for(i=1; i<size; ++i) { if(arr[i] > arr[test_sell_i]) { test_sell_i = i; } if(arr[i] < arr[test_buy_i]) { test_sell_i = i; test_buy_i = i; } if((arr[test_sell_i] - arr[test_buy_i]) > bursa_arr[2]) { bursa_arr[0] = test_buy_i; bursa_arr[1] = test_sell_i; bursa_arr[2] = (arr[test_sell_i] - arr[test_buy_i]); } }
}
Which variables initialize automatically?
global+static variables, initialized by bss at load time, assigning constants like 0.
actual type of size_t?
long unsigned int. defined in stdlib.h
What is a symbol?
Anything with a global or module level name.
In a make file, what are these?
CC = gcc
CFLAGS = -Wall -Wextra -pedantic
DEBUG_FLAGS = -g
RELEASE_FLAGS = -O2
TARGET = fooer.out
OBJS = foo.o main.o
CC: program for compiling C program
CFLAGS: flags, to give to c preprocessor
DEBUG_FLAGS: for printing debug data
RELEASE_FLAGS: at optimization level 2. function inlining (replace functiion calls with code) dead code elimination (unexecuted code yeetus) and constant folding (replace constants with actual values)
TARGET: name of the file you want to create
OBJECT: list of all object file names
In a make file, explain these:
.PHONY: all
all: main.c foo.c
$(CC) -o fooer.out main.c foo.c $(CFLAGS).
foo.o: foo.c
$(CC) -c foo.c $(CFLAGS).
clean :
rm edit $(objects)
debug :
make –debug
all is never a made result,
targeting all, requiring main.c and foo.c
create (-o) output file with specified name fooer.out using main.c and foo.c and add the CFLAGS
targeting foo.o: requiring foo.c,
compile without linker (-c) (generates .o file)
targeting phony clean: no requirements,
delete listed objects
targeting phony debug: no requirements
run first make command with debug mode
implicit rule in makefile
even without adding rules, rules are implied (assume don’t run make command if missing objects or missing command requirements)
phony targets in makefile
fake targets to permit the command to run even if there is a file with the target name. avoids file conflicts.
What is Python
general purpose, high level (close to human) programming language.
emphasizes:
readability,
object oriented,
dynamically typed,
garbage collection,
easy to learn,
free,
open source.
Interpreted VS Compiled Language
interpreted language is not converted to machine code before execution. instead interpreter reads line-by-line and executes
compiled language is compiled to machine code then executed
Dynamic VS static Typing
dynamic typing: infer variable type from assigned value. python does this.
static: must declare variable type then assign a value
Read-Eval-Print Loop
and Python Console
REPL: environment that can evaluate and print results of input expressions
Python Console is a REPL for python
Primitive Types of Python
cast them
fundamental data types of python programs:
int(Integer), float(Floats), str(String), and bool(Booleans)
Python References
objects that point to other objects
x = 10
“x” is a name object that points to the object “10”
Python Virtual Machine
manages runtime environment,
loads and executes python bytecode (given by CPython interpreter)
allows python to run on any machine that has PVM,
provides memory management, garbage collection and exception handling services.
Python Bytecode
low-level platform-dependant representation of python source code. (.pyc)
or generated by CPython interpreter, to be executed by PVM
Python Memory Management:
CPython
Block
Pool
Arena
Reference Counting
Garbage Collection
MM: allocating/freeing memory for variables/data structures
CPython iterpreter, implements generational garbage collector and reference counting
Block: fixed size block of memory size multiple of 8 bytes
Pool: 4kb of memory containing blocks
Arena: 256kb of memory containing pools
Reference Counting: tracking number of references to objects. object freed if 0.
Garbage Collection: automatically frees memory for objects no longer in use
define a function that prints the type of an object in python
def func(obect):
print( “” + str( def( object ) ) )
what do break, continue and pass do in python
break: terminates current loop, resume at next execution
continue: skip current loop iteration, resume at next iteration
pass: nothing. placeholder to be replaced with something useful.
python range()
for i in range(0,10,2)
print( “even: “ + str(i) )
range(start, stop, step)
4 differences between python and C?
python: interpreted, dynamically typed, object-oriented, high level language
C: compiled, statically typed, procedural (function-oriented), low level language
What is an interpreter? for python?
Reads/executes code. For CPython, reads and translates line by line into AST, bytecode, and lets PVM execute.
Explain the steps python source code goes through to become executable code
CPython interpreter parses source to abstract syntax tree (so that the compiler can understand)
CPython interepreter generates bytecode for each node in the AST (which tells PVM what to do with the data)
Python Virtual Machine loads and executes the bytecode
How does python manage memory
into arena of 256kb, pools of 4kb, and blocks of bytes size multiple of 8.