0% found this document useful (0 votes)
2 views4 pages

Advanced IO Unit5 Notes

Uploaded by

POKET R
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)
2 views4 pages

Advanced IO Unit5 Notes

Uploaded by

POKET R
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

Advanced I/O Notes (Unit 5)

UNIT – V : ADVANCED I/O

---------------------------------
1. I/O MULTIPLEXING AND SOCKET OPTIONS
---------------------------------
I/O Models:
There are various ways a process can perform input/output operations:
1. Blocking I/O – The process waits until the I/O completes.
2. Non-blocking I/O – The process continues executing other tasks while checking the I/O status.
3. I/O Multiplexing – A single process monitors multiple I/O streams (sockets/files) without multiple
threads.
4. Signal-driven I/O – Kernel sends a signal when I/O is ready.
5. Asynchronous I/O – The process starts the I/O and is notified when it completes.

---------------------------------
2. SELECT FUNCTION
---------------------------------
• Used to monitor multiple file descriptors (files/sockets) at once.
• Blocks until one or more descriptors are ready for read/write/error.
• Commonly used in servers handling multiple clients.

Return values of select():


- -1 → Error occurred.
- 0 → Timeout expired, no descriptors ready.
- >0 → Number of descriptors ready.

---------------------------------
3. POLL FUNCTION
---------------------------------
• Similar to select(), but uses a pollfd array (not bitmask) – more scalable for large numbers of
descriptors.
• Types of Events:
- POLLIN – Data ready for reading.
- POLLOUT – Writing possible without blocking.
- POLLERR / POLLHUP – Error or disconnect.

---------------------------------
4. RECORD LOCKING
---------------------------------
Record locking prevents multiple processes from modifying the same file data simultaneously.

Types of Locks:
- Shared Lock (F_RDLCK): Allows multiple readers, no writers.
- Exclusive Lock (F_WRLCK): Only one process can write.
- Unlock (F_UNLCK): Releases the lock.

System call: fcntl(fd, cmd, struct flock *lock)


cmd options:
- F_SETLK: Non-blocking lock.
- F_SETLKW: Waits until lock available.
- F_GETLK: Checks existing locks.

---------------------------------
5. READN AND WRITEN FUNCTIONS
---------------------------------
These helper functions ensure exact data transfer (complete n bytes).

readn(fd, buf, n): Reads exactly n bytes unless EOF.


writen(fd, buf, n): Writes exactly n bytes even if interrupted.

Used in socket programming where partial reads/writes can occur.

---------------------------------
6. SCATTER/GATHER I/O (readv and writev)
---------------------------------
readv(): Reads into multiple buffers (scatter read).
writev(): Writes from multiple buffers (gather write).

Syntax:
ssize_t readv(int fd, const struct iovec *iov, int iovcnt);
ssize_t writev(int fd, const struct iovec *iov, int iovcnt);

Used for structured data (like network packets).

---------------------------------
7. MEMORY MAPPED I/O (MMAP)
---------------------------------
Maps a file directly into the process’s memory space.
Accessed like an array, avoiding read/write system calls.

Syntax:
void *mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset);
int munmap(void *addr, size_t len);

Advantages:
- Faster (less system calls)
- Random access possible
- Good for large files and shared memory

---------------------------------
8. ASYNCHRONOUS I/O
---------------------------------
Allows non-blocking I/O operations with completion notification.

Steps:
1. Start I/O using aio_read() or aio_write().
2. Continue executing other code.
3. Check completion using aio_error().
4. Get result using aio_return().

Functions:
aio_read(), aio_write(), aio_error(), aio_return(), aio_suspend()

Useful in servers, databases, and concurrent systems.

---------------------------------
9. REMOTE LOGIN OVERVIEW
---------------------------------
Allows user to log into another system remotely (like SSH).
Protocols:
- rlogin (TCP 513): Insecure old remote login.
- telnet (TCP 23): Sends data as plain text.
- ssh (TCP 22): Encrypted secure login.

Steps:
1. Connection establishment
2. Authentication (password/key)
3. Encrypted session creation
4. Command execution or file transfer

Example commands:
ssh user@host
scp file user@host:/path
sftp user@host

---------------------------------
10. RPC TRANSPARENCY ISSUES
---------------------------------
RPC (Remote Procedure Call) executes functions on remote systems as if local.

Types of Transparency:
1. Access Transparency – Same interface for local/remote calls.
2. Location Transparency – Client doesn’t know server’s address.
3. Concurrency Transparency – Multiple clients work simultaneously.
4. Failure Transparency – Handles network failures gracefully.
5. Replication Transparency – Replicas behave as one.

Challenges:
- Failure Handling
- Network Latency
- Security and Authentication
- Data Serialization (Marshalling)
- System Heterogeneity
- Transparency Loss (timeouts/retries)

---------------------------------
11. FTP SERVER CONFIGURATION
---------------------------------
FTP (File Transfer Protocol): Transfers files between client and server (Ports 21 & 20).

Popular FTP servers:


- vsftpd (Very Secure FTP Daemon)
- proftpd
- pure-ftpd

Configuration Steps (vsftpd on Linux):


1. Install: sudo apt install vsftpd -y
2. Start & enable service:
sudo systemctl start vsftpd
sudo systemctl enable vsftpd
3. Backup config: sudo cp /etc/[Link] /etc/[Link]
4. Edit file (/etc/[Link]):
listen=YES
anonymous_enable=NO
local_enable=YES
write_enable=YES
chroot_local_user=YES
5. Create FTP directory:
sudo mkdir -p /home/ftpuser/ftp/upload
6. Restart service: sudo systemctl restart vsftpd
7. Allow firewall ports (20,21)
8. Test FTP using ftp localhost or ftp

FTP Commands:
- ls → List files
- cd → Change directory
- get filename → Download file
- put filename → Upload file
- mget *.txt → Multiple downloads
- bye → Exit session

Active vs Passive Mode:


- Active: Server connects to client (may fail with firewalls).
- Passive: Client initiates both connections – preferred.

You might also like