0% found this document useful (0 votes)
6 views3 pages

System Calls

Uploaded by

blazecyclone2020
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

System Calls

Uploaded by

blazecyclone2020
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Sure, let's break down each of these system calls:

1. **Open**:

- `open()` is a system call used to open or create a file or device. It returns a file descriptor, which is
a small, non-negative integer that the system uses to uniquely identify an open file. The file
descriptor is used in subsequent system calls to read, write, and perform other operations on the file.

- Syntax: `int open(const char *pathname, int flags);`

- Parameters:

- `pathname`: A string containing the path to the file or device to be opened.

- `flags`: A set of flags that determine the behavior of the `open()` call, such as whether the file
should be opened for reading, writing, or both, and whether the file should be created if it does not
exist.

- Return value: Returns a file descriptor on success, or -1 on failure.

2. **Create**:

- `create()` is not actually a system call itself, but it's often used in conjunction with `open()`. When
you use the `open()` system call to open a file with the `O_CREAT` flag and the file does not exist,
`open()` will create the file.

- Syntax: `int open(const char *pathname, int flags, mode_t mode);`

- Parameters:

- `pathname`: A string containing the path to the file to be opened or created.

- `flags`: A set of flags that determine the behavior of the `open()` call, including `O_CREAT`.

- `mode`: A set of permission bits that determine the file's permissions if it is created. This
parameter is only used if the `O_CREAT` flag is set.

- Return value: Returns a file descriptor on success, or -1 on failure.

3. **Read**:

- `read()` is a system call used to read data from an open file descriptor into a buffer.

- Syntax: `ssize_t read(int fd, void *buf, size_t count);`

- Parameters:

- `fd`: The file descriptor of the file from which to read.

- `buf`: A pointer to a buffer where the read data will be stored.

- `count`: The maximum number of bytes to read.


- Return value: Returns the number of bytes read on success, 0 if end of file (EOF) is reached, or -1
on failure.

4. **Write**:

- `write()` is a system call used to write data from a buffer to an open file descriptor.

- Syntax: `ssize_t write(int fd, const void *buf, size_t count);`

- Parameters:

- `fd`: The file descriptor of the file to which to write.

- `buf`: A pointer to a buffer containing the data to be written.

- `count`: The number of bytes to write.

- Return value: Returns the number of bytes written on success, or -1 on failure.

5. **Close**:

- `close()` is a system call used to close an open file descriptor.

- Syntax: `int close(int fd);`

- Parameters:

- `fd`: The file descriptor of the file to close.

- Return value: Returns 0 on success, or -1 on failure.

6. **lseek**:

- `lseek()` is a system call used to change the read/write position within a file.

- Syntax: `off_t lseek(int fd, off_t offset, int whence);`

- Parameters:

- `fd`: The file descriptor of the file to seek within.

- `offset`: The number of bytes to move the file pointer.

- `whence`: Specifies the reference point for the offset (where to start counting from), it can take
one of the following values:

- `SEEK_SET`: The beginning of the file.

- `SEEK_CUR`: The current file position.

- `SEEK_END`: The end of the file.

- Return value: Returns the new offset (position) within the file, or -1 on failure.
7. **Stat**:

- `stat()` is a system call used to retrieve information about a file.

- Syntax: `int stat(const char *pathname, struct stat *buf);`

- Parameters:

- `pathname`: A string containing the path to the file.

- `buf`: A pointer to a `struct stat` where the file information will be stored.

- Return value: Returns 0 on success, or -1 on failure.

8. **Ioctl**:

- `ioctl()` is a system call used for device-specific input/output operations. It allows for control over
various aspects of device behavior that are not covered by other system calls.

- Syntax: `int ioctl(int fd, unsigned long request, ...);`

- Parameters:

- `fd`: The file descriptor of the device.

- `request`: An integer specifying the specific operation to perform.

- Return value: Returns 0 on success, or -1 on failure.

You might also like