Skip to content

Astr0Lynx/OSN-Mini-Project-1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Operating Systems Mini-Project-1

A collection of three systems programming projects demonstrating core operating systems concepts including shell implementation, network programming, and process scheduling.

Projects

1. Shell Implementation

A custom Unix-like shell with advanced features including:

  • Command Execution: Support for built-in and external commands
  • I/O Redirection: Input (<), output (>), and append (>>) operators
  • Piping: Connect multiple commands with |
  • Job Control: Background processes with &, process monitoring
  • Command Chaining: Sequential (;) and conditional (&&) execution
  • Built-in Commands: hop, reveal, log, activities, ping, fg, bg

Location: shell/
Build: make
Run: ./shell.out

Key Features:

  • Custom command parser with token-based processing
  • Process management with fork/exec
  • Signal handling for job control
  • Command history logging

Example Usage

Starting the Shell:

cd shell
make
./shell.out

Built-in Commands:

  1. hop - Change directory (similar to cd)

    hop /path/to/directory    # Change to specified directory
    hop ~                     # Go to home directory
    hop -                     # Go to previous directory
    hop ..                    # Go up one level
  2. reveal - List directory contents (similar to ls)

    reveal                    # List current directory
    reveal -a                 # Show hidden files
    reveal -l                 # Long listing format
    reveal -al /path          # Combined flags with path
  3. log - View and execute command history

    log                       # Show all logged commands
    log purge                 # Clear command history
    log execute 3             # Execute the 3rd command from history
  4. activities - Display all background processes

    activities                # Show all running background jobs
  5. ping - Send signals to processes

    ping 1234 9              # Send SIGKILL (9) to PID 1234
    ping 5678 19             # Send SIGSTOP (19) to PID 5678
  6. fg - Bring background process to foreground

    fg 1234                  # Bring process 1234 to foreground
  7. bg - Resume stopped background process

    bg 1234                  # Resume process 1234 in background

I/O Redirection & Piping:

cat file.txt > output.txt           # Redirect output
cat file.txt >> output.txt          # Append output
sort < input.txt                    # Redirect input
ls -l | grep ".c" | wc -l          # Pipe multiple commands
cat file.txt > out.txt 2> err.txt  # Redirect stdout and stderr

Command Chaining:

mkdir test ; cd test ; touch file.txt    # Sequential execution
make && ./program                        # Execute second only if first succeeds
cat file1.txt & cat file2.txt &         # Run commands in background

2. Network Programming

Reliable UDP (RUDP) protocol implementation called S.H.A.M.:

  • File Transfer: Reliable file transmission over UDP with windowing
  • Chat Mode: Interactive messaging between client and server
  • Custom Protocol: Three-way handshake, sequence numbers, acknowledgments
  • Error Handling: Packet loss simulation, timeout handling, retransmissions
  • Logging System: Comprehensive logging for debugging (RUDP_LOG=1)

Location: networking/
Build:

cd networking
gcc -o server server.c -lssl -lcrypto
gcc -o client client.c -lssl -lcrypto

Run:

# File Transfer Mode
./server <port> [loss_rate]
./client <server_ip> <port> <input_file> <output_file> [loss_rate]

# Chat Mode
./server <port> --chat [loss_rate]
./client <server_ip> <port> --chat [loss_rate]

Protocol Features:

  • Three-way handshake (SYN, SYN-ACK, ACK)
  • Sliding window mechanism (window size: 10 packets)
  • MD5 checksum verification for file transfers
  • Configurable packet loss simulation for testing

Example Usage

File Transfer Mode:

# Terminal 1: Start server
cd networking
make
./server 8080

# Terminal 2: Send a file
./client localhost 8080 input.txt output.txt

Server receives the file and displays MD5 checksum:

Connection established with client
Receiving file...
File transfer complete
MD5: 5d41402abc4b2a76b9719d911017c592

Chat Mode:

# Terminal 1: Start server in chat mode
./server 8080 --chat

# Terminal 2: Connect client in chat mode  
./client localhost 8080 --chat
> Hello from client!

Both client and server can exchange messages interactively.

Packet Loss Simulation (for testing reliability):

# Server with 10% packet loss
./server 8080 0.1

# Client with 15% packet loss  
./client localhost 8080 input.txt output.txt 0.15

The protocol automatically retransmits lost packets.

Debug Logging:

# Enable detailed logging
export RUDP_LOG=1
./server 8080

# Logs written to server_log.txt with timestamps:
# [2024-12-20 12:30:45.123456] [LOG] RCV SYN SEQ=1234
# [2024-12-20 12:30:45.234567] [LOG] SND SYN-ACK SEQ=5678 ACK=1235

3. xv6 Scheduler Modification

Custom scheduler implementation for the xv6 operating system:

  • ReadCount System Call: New system call to track process read operations
  • Scheduler Modifications: Custom scheduling policy implementation
  • Process Statistics: Enhanced process monitoring capabilities

Location: xv6/
Files:

  • readcount.c: Implementation of the readcount system call
  • xv6_modifications.patch: Complete patch file for xv6 kernel modifications
  • report.md: Detailed implementation report

To Apply:

cd xv6-riscv
patch -p1 < ../xv6/xv6_modifications.patch
make qemu

Technical Stack

  • Language: C
  • System Calls: fork, exec, wait, pipe, dup2, signal handling
  • Networking: Socket programming (TCP), multi-threading (pthreads)
  • Build System: Make
  • OS: Unix/Linux compatible

Project Structure

.
├── shell/
│   ├── src/          # Source files (main, command, parse, process, etc.)
│   ├── include/      # Header files
│   └── Makefile      # Build configuration
├── networking/
│   ├── client.c      # Client implementation
│   ├── server.c      # Server implementation
│   └── sham.h        # Protocol definitions
└── xv6/
    ├── readcount.c                # System call implementation
    └── xv6_modifications.patch    # Kernel modifications

Building & Running

Shell

cd shell
make
./shell.out

Networking

cd networking
make
# Terminal 1
./server 8080
# Terminal 2
./client localhost 8080

xv6

Requires xv6-riscv source code:

# Clone xv6
git clone https://github.com/mit-pdos/xv6-riscv.git
cd xv6-riscv

# Apply modifications
patch -p1 < ../xv6/xv6_modifications.patch

# Build and run
make qemu

Key Concepts Demonstrated

  • Process Management: Fork, exec, wait, process states
  • Inter-Process Communication: Pipes, signals
  • File I/O: Redirection, file descriptors, dup2
  • Network Programming: Sockets, client-server architecture
  • Concurrency: Multi-threading, synchronization
  • System Calls: Implementation and usage
  • Memory Management: Dynamic allocation, buffer handling
  • Error Handling: Robust error checking and recovery

Implementation Highlights

Shell

  • Parser: Tokenizes input with support for operators, quotes, and escapes
  • Execution Engine: Handles foreground/background processes, pipelines
  • Job Control: Process groups, signal handling (SIGCHLD, SIGINT)
  • History: Command logging with execution tracking

Networking

  • Protocol: Custom reliable UDP (S.H.A.M.) with sliding window
  • Handshake: Three-way connection establishment (SYN, SYN-ACK, ACK)
  • Reliability: Sequence numbers, acknowledgments, retransmissions
  • Flow Control: Fixed window size with buffer management
  • Error Recovery: Timeout handling and packet loss simulation

xv6 Scheduler

  • System Call: Added readcount() to kernel interface
  • Scheduler Logic: Modified process selection algorithm
  • Statistics: Enhanced process structure with read counters

Author

Guntesh Singh

License

MIT License