Python Questions and Answers – Operating System

This set of Python Questions & Answers for Exams focuses on “Operating System”.

1. What does os.name contain?
a) the name of the operating system dependent module imported
b) the address of the module os
c) error, it should’ve been os.name()
d) none of the mentioned
View Answer

Answer: a
Explanation: It contains the name of the operating system dependent module imported such as ‘posix’, ‘java’ etc.

2. What does print(os.geteuid()) print?
a) the group id of the current process
b) the user id of the current process
c) both the group id and the user of the current process
d) none of the mentioned
View Answer

Answer: b
Explanation: os.geteuid() gives the user id while the os.getegid() gives the group id.

3. What does os.getlogin() return?
a) name of the current user logged in
b) name of the superuser
c) gets a form to login as a different user
d) all of the mentioned
View Answer

Answer: a
Explanation: It returns the name of the user who is currently logged in and is running the script.
advertisement
advertisement

4. What does os.close(f) do?
a) terminate the process f
b) terminate the process f if f is not responding
c) close the file descriptor f
d) return an integer telling how close the file pointer is to the end of file
View Answer

Answer: c
Explanation: When a file descriptor is passed as an argument to os.close() it will be closed.

5. What does os.fchmod(fd, mode) do?
a) change permission bits of the file
b) change permission bits of the directory
c) change permission bits of either the file or the directory
d) none of the mentioned
View Answer

Answer: a
Explanation: The arguments to the function are a file descriptor and the new mode.
Note: Join free Sanfoundry classes at Telegram or Youtube

6. Which of the following functions can be used to read data from a file using a file descriptor?
a) os.reader()
b) os.read()
c) os.quick_read()
d) os.scan()
View Answer

Answer: b
Explanation: None of the other functions exist.

7. Which of the following returns a string that represents the present working directory?
a) os.getcwd()
b) os.cwd()
c) os.getpwd()
d) os.pwd()
View Answer

Answer: a
Explanation: The function getcwd() (get current working directory) returns a string that represents the present working directory.
advertisement

8. What does os.link() do?
a) create a symbolic link
b) create a hard link
c) create a soft link
d) none of the mentioned
View Answer

Answer: b
Explanation: os.link(source, destination) will create a hard link from source to destination.

9. Which of the following can be used to create a directory?
a) os.mkdir()
b) os.creat_dir()
c) os.create_dir()
d) os.make_dir()
View Answer

Answer: a
Explanation: The function mkdir() creates a directory in the path specified.
advertisement

10. Which of the following can be used to create a symbolic link?
a) os.symlink()
b) os.symb_link()
c) os.symblin()
d) os.ln()
View Answer

Answer: a
Explanation: It is the function that allows you to create a symbolic link.

Sanfoundry Global Education & Learning Series – Python.

To practice all exam questions on Python, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.