Chapter 3 Flashcards
(42 cards)
What are the three purposes of operating systems?
Provide reliable and efficient concurrent execution of multiple
processes.
Provide mechanisms for inter-process communication
Simplify application development
Define a process.
Instance of running program that includes all system resources used for that program. Has a unique PID. Processes only interact with each other through kernel (ecall instructions).
How are processes created using fork?
fork() system call creates a copy of the calling process and assigns it a new PID. Both the parent and the child processes continue from the same fork() call, but in child fork() returns 0, in parent it does not.
What does the wait system call do?
wait(int *status)
Puts calling process to sleep until one of its children processes terminates with exit(status)
What does the exec command do?
exec(prog, arguments[]) - replaces the running program in the calling process with the program in the file prog. first argument is name of file, subsequent arguments are command line arguments.
Syntax for opening, reading, writing into a file.
fd = open(“filename”, flags, permissions)
write(fd, message, number of bytes);
read(fd, data, num);
close(fd)
What are the flags for the open command?
O_RDONLY (read only)
O_WRONLY (write only)
O_RDWR (read and write)
O_CREATE (whether to create if not there)
Pipe syntax.
int p[2];
pipe(p);
read from p[0]
write to p[1]
Syntax of simple commands in bash.
command arg1 arg2 … argN
Distinguish between operands and options.
Operands are object arguments
Options modify default behavior of the command.
What do \, ‘ and “ do?
\ removes special meaning of following symbol.
‘ removes special meaning of all symbols surrounded by them.
“ removes special meaning of all symbols surrounded by them except $, \ and ``.
How are non-built in commands run?
If the command specified by the user is not a built-in command, the shell tries to find an executable file in the file system with the name matching the command and runs it as a child process using exec().
What does pwd do?
Print the full name of the current working directory.
How does one run an executable file from the current working directory?
./exeName
What do the nano and cat fileName commands do?
nano -> starts a text editor
cat fileName -> displays the contents of the file with the name file.
Inside the nano text editor how do you save changes.
Ctrl - O to write out data
Ctrl - X to exit
How do you copy, move and delete files in UNIX?
cp foo bar -> copy the contents of file foo into file bar (create if doesn’t exist)
mv foo bar -> move the file foo into bar
rm foo delete file foo
ln foo bar (create a hard link bar to the file foo)
How do u make and remove directories?
mkdir dirname = create directory with the name dirname
rmdir dirname = delete directory with the name dirname
To instruct shell that process should take input from file, write output to file and output error messages to file, syntax.
command arg1 <inputFile>outputFile 2>errorFile (arg2 ... argN)</inputFile>
When we want to disregard output data what can we do?
Redirect output stream to /dev/null
What is syntax to send output and errors to same file? What does»_space; do?
command >outputFile 2>&1
Using»_space; means it appends instead of overwriting.
How can a string be passed as a command line argument?
«<string
Use bc to calculate 2^128.
bc «< “2^128”
I want to pass as input everything in a file until a particular word.
«word
/
/
contents we want to append
/
/
word