logoISU  

CS456 - Systems Programming

Spring 2023

Displaying ./code/quiz/q1.txt


1. What system call opens a file descriptor?
open

2. What system call writes data from a buffer to a file descriptor?
write

3. What system call reads from a file descriptor?
read

4. What system call closes a file descriptor?
close

5. What system call sets the file pointer position in a file?
lseek
 
6. This system call is the only way to create a new process in Linux
fork

7. File descriptor 0 refers to what file?
stdin OR standard input
 
8. File descriptor 1 refers to what file?
stdout
standard output

9. File descriptor 2 refers to what file?
stderr
standard error

10. open usually takes two arguments. What two arguments are those?
pathname and flags
 
11. open returns this value if it fails to open the file
-1
 
12. Using this flag with open will open the file for reading
O_RDONLY
 
13. Using this flag with open will open the file for writing
O_WRONLY

14. Using this flag with open will open the file for reading and writing
O_RDWR
 
15. Using this flag with open will append data to the end of a file
O_APPEND
 
16. Using this flag with open will create a file if it doesn't exist
O_CREAT

17. Using this flag with open will delete all the data in a file upon opening
O_TRUNC
 
18. close returns this value when sucessful
0

19. The read system call takes three arguments. What are these arguments and what do they do?
1. the file descriptor
2. the buffer
3. the number of bytes read

read will attempt to read up to the specified number of bytes from the file descriptor and store
the data in the buffer

20. The write system call takes three arguments. What are these arguments and what do they do?
1. file descriptor
2. the buffer
3. number of bytes written

write will write up to the specified number of bytes from the buffer into the file referred to by the file descriptor.

21. What does the following code do?
write(1, “Hello”, 5);

prints "Hello" to standard output (your screen)


22. What does the following code do?
int fd = open("bar.txt", O_WRONLY | O_TRUNC | O_CREAT, 0666);

opens "bar.txt" for writing, truncating its contents or creating it if it does not exist:


23. This type of function is a kernel function that allows you to enter kernel mode and access a hardware resource.
System Call

24. This type of function is a function provided by a programming library to complete a task.
Library Call

25. Modern processors have two modes of execution: 
user and kernel

26. What header file(s) do i need to include if I wanted to use open?
<fcntl.h>

27. What header file(s) do i need to include if I wanted to use read?
<unistd.h>

28. What header file(s) do i need to include if I wanted to use write?
<unistd.h>

29. What does the following code do?
int fd = open("foo.txt", O_RDONLY);
opens foo.txt for reading only