Unix System Overview Flashcards

1
Q

what is an operating system?

A

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.

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

What is the interface to the kernel?

A

It is a layer of software called the Systems calls.

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

What is Libraries used for in this?

A

contains common functions which are built on top of the system call interface.

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

What is the shell?

A

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

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

What does “other software “ refer to when talking operating systems?

A

software includes: system utilities, applications , shells, libraries of common functions, ect.

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

give an example of an operating system that uses Linux

A

GNU/Linux operating system (commonly referenced as Linux).

Linux is the kernel used by the GNU operating system.

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

What would you find if you look at our entry in the password file?

A
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.)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what is an interactive shell?

A

the user input to a shell is normally from the terminal

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

What is a shell script?

A

A file from which commands will be entered in to run.

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

What are the only 2 chars that cannont appear in a filename?

A

slash character (/) and the null character

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

how many filenames are automatically created whenever a new directory is created?

A

Two.
current directory
and the parent directory.
(fun fact: in the root directory the dot-dot is the same as dot)

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

describe C preprocessor

A

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 )

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

describe modifier “const”

A

can make types or pointers read only/ cant change without casting (const) away.

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

difference between const and static

A

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.

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

describe pointer

A

a datatype in C and is an address of some place in memory.

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

list 4 things pointers can point to in C

A

global variables
local variables
functions
dynamically allocated memory

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

describe what this means:

pointers and arrays are same concept in C

A

arrays use pointer
but not all pointers are arrays
*note: int *dp
dp[cnt] == *(dp+cnt)

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

where does your file system start?

A

everything starts in root directory whose name is the single char /.

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

what does function stat and fstat return?

A

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

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

what are names in a directory called?

A

filenames

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

what is it called when a pathname begins with a slash?

A

absolute pathname

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

what is it called when a pathname does not begin with a slash?

A

relative pathname

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

what does relative pathname refer to?

A

refers to files relative to the current directory

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

what command is used to compile a c file into an exicutable

A

cc programName.c

gcc for GNU C complilation

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

what is working directory

A

the directory from which all relative pathnames are interpreted.

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

how can a process change its working directory

A

by using the chdir fucntion

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

describe what this pathname tells

/usr/lib/lint

A

is an absolute pathname that refers to the file or directory lint in the directory lib, in the Root directory usr

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

what is our working directory when we log in?

A

it is set to our home directory.

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

where is our home directory obtained?

A

it is obtained from our entry in the password file

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

describe file descriptors

A

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

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

what 3 descriptors does shell open whenever a new program is run?

A

standard input 0 (buffered), standard output 1 (buffered), standard error 2 (unbuffered)

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

unbuffered I/O is provided by functions…

A

open, read, write, lseek, and close. these functions all work with file descriptors

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

describe a program

A

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.

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

describe process

A

an executing instance of a program. every process is given a unique process ID always positive number

35
Q

what is getpid()

A

function that returns the process ID

36
Q

describe ps command

A

it is process status command and provides info about current running process (PID, TIME, TTY, CMD)

37
Q

describe fork()

A

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.

38
Q

describe execlp()

A

called by child process to execute comand read from standard input. this replaces the child process with the new program file.

39
Q

what does “spawning a new process” mean

A

when fork used followed by exec.

40
Q

describe getuid()

A

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

41
Q

describe getgid()

A

returns the group id of the calling process

42
Q

describe getpid()

A

returns the process ID of the calling process

43
Q

what is system calls?

A

request to os, typically a trap instruction, often an assembly wrapper, return values (return info about system call) or error number

44
Q

char *strerror(int errnum)

A

returns pointer to message string

45
Q

void perror(const char *msg)

A

produces an error message on the standard error based on value of errno.

46
Q

describe signals

A

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

47
Q

chmod()

A

changes file mode bits

48
Q

describe system call

A

function that invokes appropriate kernal service

49
Q

what is difference between system calls and library functions

A

we can replace library functions (user process), if desired where as the system calls (kernel) usaully cant be replaced

50
Q

describe open()

A
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
51
Q

describe creat()

A

new file can also be created by creat() function

returns file descriptor opened for write-only of OK, error -1.

52
Q

describe int close(int fd)

A

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

53
Q

describe lseek(int fd, off_t offset, int whence)

A

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

54
Q

read(int fd, void *buf, size_t nbytes)

A

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

55
Q

write(int fd, const void *buf, size_t nbytes)

A

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

56
Q

dup(int fd)

dup2(int fd, int fd2)

A

ducliates an existing file descriptor

57
Q

int fnctl(int fd, int cmd)

A

manipulates fd, can change properties of a file that is already open.

58
Q

int ioctl(int d, request, *argptr)

A

manipulates underlying device parameters, catchall fro i/o operations. used when anything cant be expressed using one of the other functions we know of.

59
Q

name 7 file types

A
regular file
directory file
character special file
block special file
symbolic link
fifo
socket (network)
60
Q

disk

A

partition 1 | partition 2 | ….. |

61
Q

single partition

A

file system 1 | file system 2 | file system | … |

62
Q

single file system

A

boot | super | inodes | data blocks |

63
Q

describe boot

A

bootstrap program

64
Q

describe super

A

contains info about partition

65
Q

describe inodes

A

one per real file

66
Q

data blocks

A

both files and directories

67
Q

file system blocks

A

usually power of 2

68
Q

directory:

A

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

69
Q

describe inode

A
owner, group, permissions
file type
num of links
size, num of blocks
times (accessed modified status_change)
70
Q

describe access to data blocks

A
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
71
Q

int stat(const char *path, struct stat *sb)

A

return inf about files no premissions required.

reterive info about file pointed to by pathname

72
Q

int lstat(const char *path, struct stat *sb)

A

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

73
Q

int fstat(int fd, struct stat *sb)

A

return inf about files no premissions required.
reterive info about file pointed to by pathname
except file is specified by file descriptor

74
Q

int access(const char *path, int mode)

A

checks whether colling process can access the file pathname.

75
Q

int chmod(const char *path, mode_t mode)

A

system calls change the permissions of a file specified whose pathname is given in pathname

76
Q

int chown(const char *pathname, uid_t owner, gid_t group);

A

changes the ownership of the file specified by pathname

77
Q

int truncate(const char *path, off_t length);

A

functions cause the regular file named by path to be truncated to a size of precisely length bytes

78
Q

int link(const char *oldpath, const char *newpath);

A

creates a new link to an existing file, works only on files in the same file system. need write permissions

79
Q

if sicky bit is off or on how does affect unlink()

A

if off you dont have to own file to unlink
if on then must own file
either way must have execute permission

80
Q
symbolic links
int symlink(const char *target, const char *linkpath);
A

not a hard link
unlink removes only stored name
creates a symbolic linke “linkpath” which contains the string target.

81
Q

describe macro

A

fragment of code which is given a name.

82
Q

what is the man pages?

A

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

83
Q

formats: %[flags][fieldwidth][.precision][modifier]conv

what kind of flags can be added in outputted formats?

A
flags:
- Left justify
\+ Always sign the number
0 zero padded
(space) blank space for +
84
Q

what does printf() return?

A

it tells you how many characters were printed