Question

In: Computer Science

What are System calls. Provide 6 file and directory system calls

What are System calls. Provide 6 file and directory system calls

Solutions

Expert Solution

Systen call provides the interface between a process & operating system, these calls are generally available in assembly language instruction and they are usually listed in various mannuals used by Assembly Language proframmers.

System allows system calls to be made directly from a high level language program , in which case the calls normally made by pre-defined functins and subroutine calls.

Several languages such as C,C++ etc, have defined to replace Assembly language for system programming. These languages allow system calls to made directly.

For Example: UNIX system calls may be invoke directly from C orC++ program. System calls are modern microsoft windows platform are part of the Win 32 API (Application program interface).

Directory for system call.

1.  System call OPEN

Opening or creating a file can be done using the system call open. The syntax is:

#include <sys/types.h>

#include <sys/stat.h>

#include <fcntl.h>

int open(const char *path,

   int flags,... /* mode_t mod */);

O_RDONLY

            Opens the file for reading.

O_WRONLY

            Opens the file for writing.

O_RDWR

            The file is opened for reading and writing.

O_APPEND

            It writes successively to the end of the file.

O_CREAT

            The file is created in case it didn\92t already exist.

O_EXCL

            If the file exists and O_CREAT is positioned, calling open will fail.

O_NONBLOCK

In the case of pipes and special files, this causes the open system call and any other future I/O operations to never block.

O_TRUNC

            If the file exists all of its content will be deleted.

O_SYNC

            It forces to write on the disk with function write. Though it slows down all the system, it can be useful in critical situations.

The third argument, mod, is a bitwise OR made between a combination of two from the following list:

S_IRUSR, S_IWUSR, S_IXUSR

Owner: read, write, execute.

S_IRGRP, S_IWGRP, S_IXGRP

Group: read, write, execute.

S_IROTH, S_IWOTH, S_IXOTH

Others: read, write, execute.

2:

System call CREAT

A new file can be created by:

#include <sys/types.h>

#include <sys/stat.h>

#include <fcntl.h>

int creat(const char *path, mode_t mod);

The function returns the file descriptor or in case of an error it returns the value -1. This call is equivalent with:

     open(path, O_WRONLY | O_CREAT | O_TRUNC, mod);

3:

System call READ

When we want to read a certain number of bytes starting from the current position in a file, we use the read call. The syntax is:

#include <unistd.h>

ssize_t read(int fd, void* buf, size_t noct);

4:

System call WRITE

For writing a certain number of bytes into a file starting from the current position we use the write call. Its syntax is:

#include <unistd.h>

ssize_t write(int fd, const void* buf, size_t noct);

5:

System call CLOSE

For closing a file and thus eliminating the assigned descriptor we use the system call close.

#include <unistd.h>

int close(int fd);

The function returns 0 in case of success and -1 in case of an error. At the termination of a process an open file is closed anyway.

6:

System call LSEEK

To position a pointer (that points to the current position) in an absolute or relative way can be done by calling the lseek function. Read and write operations are done relative to the current position in the file. The syntax for lseek is:

#include <sys/types.h>

#include <unistd.h>

off_t lseek(int fd, off_t offset, int ref);

These all about the system call and its directory . Dear Student if you still have any query then ask me again..Thankyou!!!


Related Solutions

Demonstrate your grasp of the Unix file system by constructing a directory structure as follows: In...
Demonstrate your grasp of the Unix file system by constructing a directory structure as follows: In your home ( ~ ) directory, create a directory named “UnixCourse”. This directory will be used in the remaining assignments of this course, as well as this one. Several of the commands that you will issue in this course will examine files in this directory and, in some cases, send me a listing of those files or even copies of those files for grading...
In a UNIX-like file system, a directory typically contains: A. filenames and i-nodes B. permission information,...
In a UNIX-like file system, a directory typically contains: A. filenames and i-nodes B. permission information, pointers to direct blocks C. filenames and ownership information D. filenames, i-nodes, major device numbers and minor device numbers
Parse the dirent struct to see if an entry is a directory or a file. If...
Parse the dirent struct to see if an entry is a directory or a file. If it is a directory, prepend "./" to the filename before printing it out. Include a main that does this below. Please do the above code using C language.
Create a file named work.sh in your hw5 directory. Give this file read and write permission...
Create a file named work.sh in your hw5 directory. Give this file read and write permission (no execute permissions) for you alone. No other account should have any access privileges to this file. Change the permissions on the work.sh file so you have read and write permissions. Give everybody else, including the group, read permissions only. Give yourself read, write and execute permissions to the file work.sh. Give everyone else, including the group, execute permissions only. Create a directory named...
If possible, please answer all 4 questions. Thanks! :) 35. What file in the /proc directory...
If possible, please answer all 4 questions. Thanks! :) 35. What file in the /proc directory can be used to list the features supported by your system’s CPU? 36. Which of the following commands can be used to insert a kernel module into the Linux kernel? (Choose all that apply.) a. insmod b. modprobe c. lsmod d. depmod
Go to your “Documents” directory; a) Create a file “file1” with the text “hello” in it;...
Go to your “Documents” directory; a) Create a file “file1” with the text “hello” in it; Provide command and screenshot. b) Create a hard link named “file2” linked to “file1”; c) Create a soft link named “soft1” linked to “file1”; create another soft link named “soft2” linked to “file2”. d) View information of the 4 files (what command should you use to produce output) – how do you verify which file is a hard link and which file is a...
In the two-level directory, if a user refers to a particular file then__________________ Select one: a....
In the two-level directory, if a user refers to a particular file then__________________ Select one: a. first UFD (user file directory) is searched, then MFD (master file directory) b. only his/her own UFD (user file directory) is searched (WRONG)c. first MFD (master file directory) is searched, then UFD (user file directory) d. only MFD (master file directory) is searched When the exclusive lock is applied to a file then _____________ Select one: a. many processes can read and write to...
You first needs to create a file called “myJS.js” in your project directory. Then, include the...
You first needs to create a file called “myJS.js” in your project directory. Then, include the AngularJS library and myJS.js in the header of the index.html page. Now, you need to define your angular application and a controller in this file such that the controller has the following variables with these initial values: name = "Alex Cool"; faculty= "Faculty of Busienss and IT"; university = {name:"University of Ontario Institute of Technology", url:"http://www.uoit.ca"}; contacts = {email:"[email protected]", phone:"xxx-xxx-xxxx"}; skills = [ {name:...
PYTHON - You are given a data.csv file in the /root/customers/ directory containing information about your...
PYTHON - You are given a data.csv file in the /root/customers/ directory containing information about your customers. It has the following columns: ID,NAME,CITY,COUNTRY,CPERSON,EMPLCNT,CONTRCNT,CONTRCOST where ID: Unique id of the customer NAME: Official customer company name CITY: Location city name COUNTRY: Location country name CPERSON: Email of the customer company contact person EMPLCNT: Customer company employees number CONTRCNT: Number of contracts signed with the customer CONTRCOST: Total amount of money paid by customer (float in format dollars.cents) Read and analyze the...
In the Linux file system, the majority of the file system code exists in the kernel....
In the Linux file system, the majority of the file system code exists in the kernel. research the anatomy of the Linux file system, then discuss the effectiveness or ineffectiveness of this type of architecture. In addition, explain why you feel the way you do and provide support
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT