In: Computer Science
For each of the following Unix system calls, give a condition that causes it to fail: open, read, fork, execve, unlink.
open():
The open() system call will when the required file(resource) is not present in specified Directory path
read():
1)when the seek pointer(file offset) is at the end of the file, since there are no words(bytes) to read the read() will fails and it returns 0.
2)When there are no bytes to read in a file i.e., byte count=0 , then the read() will fail
fork():
fork() mainly fails when there is no freespace memory left. i.e., the kernel is not able to copy the parent process page tables to the child process. we can know that the fork is failed whenever fork() returns -1.
fork() returns -1, whenever the bit 'errno' inside the fork() is SET.
execve():
execve() fails and returns to the calling process whenever:
The number of bytes(words) in a newly created process's argument list is bigger than the limit imposed by OS
unlink():
unlink() is used to delete the file names.
when the filename we want to unlink does not exist in the specified path then the unlink() system call fails.
On success unlink() returns "0" , on failure it returns "-1"
These are some of the conditions where the above mentioned system calls fail
***please give a like if you are satisfied with the answer. if you have any doubts or you need any further information ask me through comments. THANK YOU! ***