Unix System Overview Flashcards
what is an operating system?
the software that controls the hardware resourses of the computer. and provides an environment under which programs can run. (generally called the kernel).
In broad sense, an operating system is the kernel and all the other software that makes a computer useful.
What is the interface to the kernel?
It is a layer of software called the Systems calls.
What is Libraries used for in this?
contains common functions which are built on top of the system call interface.
What is the shell?
it is a special application that provides an interface for running other applications.
is a command line interperater that reads user input and executes commands
What does “other software “ refer to when talking operating systems?
software includes: system utilities, applications , shells, libraries of common functions, ect.
give an example of an operating system that uses Linux
GNU/Linux operating system (commonly referenced as Linux).
Linux is the kernel used by the GNU operating system.
What would you find if you look at our entry in the password file?
login name encrypted password, numeric user ID (205) numeric group ID (105) a comment field home directory shell program (*note: newer systems have moved encrypted password to a Different file.)
what is an interactive shell?
the user input to a shell is normally from the terminal
What is a shell script?
A file from which commands will be entered in to run.
What are the only 2 chars that cannont appear in a filename?
slash character (/) and the null character
how many filenames are automatically created whenever a new directory is created?
Two.
current directory
and the parent directory.
(fun fact: in the root directory the dot-dot is the same as dot)
describe C preprocessor
Macro processor automatically used by C compiler to transform ur program before compilation. (ablility for inclusion of header files, macro expansions, and line conditional compilation, system files )
describe modifier “const”
can make types or pointers read only/ cant change without casting (const) away.
difference between const and static
static variable can be change anywhere within its scope. but can only be used within what the function it is in.
so if you call a static global variable then can be used anywhere in that file.
describe pointer
a datatype in C and is an address of some place in memory.
list 4 things pointers can point to in C
global variables
local variables
functions
dynamically allocated memory
describe what this means:
pointers and arrays are same concept in C
arrays use pointer
but not all pointers are arrays
*note: int *dp
dp[cnt] == *(dp+cnt)
where does your file system start?
everything starts in root directory whose name is the single char /.
what does function stat and fstat return?
it returns a structure of information containing all the attributes of a file. such as type of file, directory size of file, owner of file, permissions for file, last modified
what are names in a directory called?
filenames
what is it called when a pathname begins with a slash?
absolute pathname
what is it called when a pathname does not begin with a slash?
relative pathname
what does relative pathname refer to?
refers to files relative to the current directory
what command is used to compile a c file into an exicutable
cc programName.c
gcc for GNU C complilation
what is working directory
the directory from which all relative pathnames are interpreted.
how can a process change its working directory
by using the chdir fucntion
describe what this pathname tells
/usr/lib/lint
is an absolute pathname that refers to the file or directory lint in the directory lib, in the Root directory usr
what is our working directory when we log in?
it is set to our home directory.
where is our home directory obtained?
it is obtained from our entry in the password file
describe file descriptors
small positive nums that kernel uses to identify the files being accessed by a particular process.. all open files are referred to by file descriptors
what 3 descriptors does shell open whenever a new program is run?
standard input 0 (buffered), standard output 1 (buffered), standard error 2 (unbuffered)
unbuffered I/O is provided by functions…
open, read, write, lseek, and close. these functions all work with file descriptors
describe a program
is an executable file residing on disk in a directory. program is read into memory and is executed by kernel as a result of 1 of 6 exec functions.
describe process
an executing instance of a program. every process is given a unique process ID always positive number
what is getpid()
function that returns the process ID
describe ps command
it is process status command and provides info about current running process (PID, TIME, TTY, CMD)
describe fork()
creates a new process. parent and newly created process child. returns 0 for child. and returns the PID of the child process to the fork() of parent.
describe execlp()
called by child process to execute comand read from standard input. this replaces the child process with the new program file.
what does “spawning a new process” mean
when fork used followed by exec.
describe getuid()
returns user id (numeric value that identifies us to the system. assigned by the system adminastrator when our login name is assigned)of calling process
describe getgid()
returns the group id of the calling process
describe getpid()
returns the process ID of the calling process
what is system calls?
request to os, typically a trap instruction, often an assembly wrapper, return values (return info about system call) or error number
char *strerror(int errnum)
returns pointer to message string
void perror(const char *msg)
produces an error message on the standard error based on value of errno.
describe signals
a technique used to notify process that some condition has occurred. 3 typical choices when dealing with signals. ignore signal, defualt action occur, and catching
chmod()
changes file mode bits
describe system call
function that invokes appropriate kernal service
what is difference between system calls and library functions
we can replace library functions (user process), if desired where as the system calls (kernel) usaully cant be replaced
describe open()
a file is opened or created by calling this function. 3 flags: read only (0) O_RDONLY write only (1) O_WRONLY read and right (2) O_RDWR
describe creat()
new file can also be created by creat() function
returns file descriptor opened for write-only of OK, error -1.
describe int close(int fd)
an open file is closed by calling this function.
returns 0 if OK
returns -1 if error
when process terminates all open files are closed automatically by kernel
describe lseek(int fd, off_t offset, int whence)
an open files offset can be set explicitly by calling lseek
returns new location of file pointer.
whence:
SEEK_SET - offset bytes from start of file
SEEK_CUR - offset bytes from current location
SEEK_END - offset bytes from end of the file
read(int fd, void *buf, size_t nbytes)
returns num of bytes read, 0 if end of file, -1 for error
Data is read from open file with this function
starts at files current offset and incremented by num of offset read
write(int fd, const void *buf, size_t nbytes)
returns num of bytes written if ok, -1 for error
data is written to an open file with the write function
starts at files current offset increments by num of bytes actually written
dup(int fd)
dup2(int fd, int fd2)
ducliates an existing file descriptor
int fnctl(int fd, int cmd)
manipulates fd, can change properties of a file that is already open.
int ioctl(int d, request, *argptr)
manipulates underlying device parameters, catchall fro i/o operations. used when anything cant be expressed using one of the other functions we know of.
name 7 file types
regular file directory file character special file block special file symbolic link fifo socket (network)
disk
partition 1 | partition 2 | ….. |
single partition
file system 1 | file system 2 | file system | … |
single file system
boot | super | inodes | data blocks |
describe boot
bootstrap program
describe super
contains info about partition
describe inodes
one per real file
data blocks
both files and directories
file system blocks
usually power of 2
directory:
name, inode # | name, inode # | … |
each entry in directory is a link
inode contains num of links
file (inode and data) in not deleted until like count is 0
describe inode
owner, group, permissions file type num of links size, num of blocks times (accessed modified status_change)
describe access to data blocks
n data block pointer (disk address) - inode -> data block 1 - indirect block - inode -> pointer block -> data block 1 - 3 level indirect block - inode -> ptr block -> ptr block -> ptr block -> data block
int stat(const char *path, struct stat *sb)
return inf about files no premissions required.
reterive info about file pointed to by pathname
int lstat(const char *path, struct stat *sb)
return inf about files no premissions required.
reterive info about file pointed to by pathname
except if pathname is a symbolic linke then return info about link itself, not the file that it refers to
int fstat(int fd, struct stat *sb)
return inf about files no premissions required.
reterive info about file pointed to by pathname
except file is specified by file descriptor
int access(const char *path, int mode)
checks whether colling process can access the file pathname.
int chmod(const char *path, mode_t mode)
system calls change the permissions of a file specified whose pathname is given in pathname
int chown(const char *pathname, uid_t owner, gid_t group);
changes the ownership of the file specified by pathname
int truncate(const char *path, off_t length);
functions cause the regular file named by path to be truncated to a size of precisely length bytes
int link(const char *oldpath, const char *newpath);
creates a new link to an existing file, works only on files in the same file system. need write permissions
if sicky bit is off or on how does affect unlink()
if off you dont have to own file to unlink
if on then must own file
either way must have execute permission
symbolic links int symlink(const char *target, const char *linkpath);
not a hard link
unlink removes only stored name
creates a symbolic linke “linkpath” which contains the string target.
describe macro
fragment of code which is given a name.
what is the man pages?
man is the system’s manual pager.
the section no. are as follow:
1: executable programs or shell commands
2: system calls (functions provided by kernels)
3: Library calls (functions within program libraries)
4: Special files (usually found in /dev)
5: File formats and conventions
7: miscellaneous (including macro packages)
8: system administration commands (usually only for root)
9: Kernel routines
formats: %[flags][fieldwidth][.precision][modifier]conv
what kind of flags can be added in outputted formats?
flags: - Left justify \+ Always sign the number 0 zero padded (space) blank space for +
what does printf() return?
it tells you how many characters were printed