Skip to content

odeliyach/Linux-System-Programming

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

33 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Linux System Programming Portfolio

High-Performance C11 Systems Programming: Process Management, IPC & Concurrent Data Structures

CI Build Passing C License


🎯 What This Portfolio Demonstrates

This repository showcases professional systems programming skills through two focused C11 implementations:

  1. Mini Shell - Low-level process lifecycle management with multi-stage pipelines, signal handling, and proper resource cleanup
  2. Thread-Safe Queue - Lock-based producer-consumer coordination achieving ~400K items/sec with per-thread condition variables

Key Skills Demonstrated

βœ… Memory Management - Zero leaks (Valgrind-verified), explicit ownership semantics βœ… Concurrency - C11 threads, mutexes, condition variables, atomic operations βœ… Systems Programming - POSIX signals, fork/exec/pipe, process groups, file descriptor handling βœ… Performance Engineering - Optimized synchronization patterns, throughput benchmarking βœ… Production Readiness - CI/CD pipeline, Docker containerization, comprehensive testing strategy


πŸš€ Quick Start

Build and Run

# Clone the repository
git clone https://github.com/odeliyach/Linux-System-Programming.git
cd Linux-System-Programming

# Build all targets
make all

# Run the shell
./bin/myshell

# Run queue tests
make test

Docker Deployment

# Build container
docker build -t linux-sys-prog .

# Run queue test
docker run --rm linux-sys-prog ./queue_test

# Interactive shell
docker run --rm -it linux-sys-prog ./myshell

πŸ“‚ Project Structure

Linux-System-Programming/
β”œβ”€β”€ src/                          # Source code (new structure)
β”‚   β”œβ”€β”€ shell/                    # Mini shell implementation
β”‚   β”‚   β”œβ”€β”€ myshell.c            # Core shell logic (fork/exec/pipe)
β”‚   β”‚   └── shell_main.c         # Shell REPL driver
β”‚   └── queue/                    # Thread-safe queue
β”‚       └── queue.c              # Concurrent FIFO implementation
β”œβ”€β”€ include/                      # Public headers
β”‚   └── queue.h                  # Queue API
β”œβ”€β”€ tests/                        # Test suites
β”‚   └── queue_test.c             # Producer-consumer benchmark
β”œβ”€β”€ System_Programming_Projects/  # Legacy structure (maintained for compatibility)
β”œβ”€β”€ docs/                         # Documentation (technical analysis, feedback, study plan)
β”œβ”€β”€ .github/workflows/            # CI/CD pipeline
β”‚   └── ci.yml                   # Build and test automation
β”œβ”€β”€ Makefile                      # Professional build system
β”œβ”€β”€ Dockerfile                    # Production container
β”œβ”€β”€ TESTING.md                    # Testing strategy and edge cases
└── README.md                     # This file

πŸ”§ Build System

Available Targets

make all      # Build all targets (default)
make test     # Run test suite
make check    # Build and test (CI-friendly)
make debug    # Build with debug symbols (-g -O0)
make clean    # Remove build artifacts
make install  # Install to PREFIX (default: /usr/local)
make help     # Show all targets

Compiler Flags

  • -std=c11 - C11 standard compliance
  • -Wall -Wextra -Werror - Strict warnings as errors
  • -O2 - Optimization level 2 (release builds)
  • -pthread - POSIX threads support

πŸ“Š Performance Characteristics

Thread-Safe Queue Throughput

Configuration Items Elapsed Throughput Notes
2P / 2C baseline 100 0.0002s 447K items/s Per-thread condition variables
4P / 4C stress 400 0.0009s 444K items/s Scales linearly with threads

Hardware: Ubuntu 22.04, Intel Xeon (GitHub Actions runner)

Key Optimization: Direct producer-to-consumer handoff via per-waiter condition variables reduces context switches compared to broadcast wakeups.


πŸ› οΈ Component Details

1. Mini Shell (src/shell/)

Capabilities:

  • Multi-stage pipelines (up to 10 commands)
  • Input/output redirection (<, >)
  • Background execution (&)
  • Proper signal handling (SIGINT, SIGCHLD)
  • Zombie process prevention

Architecture:

prepare() β†’ Install signal handlers (SIGINT ignore, SIGCHLD reaper)
process_arglist() β†’ Fork/exec with pipe() + dup2() wiring
finalize() β†’ Restore default signal dispositions

Signal Handling Strategy:

  • Parent ignores SIGINT (Ctrl+C) β†’ children inherit default handler
  • SIGCHLD handler with waitpid(WNOHANG) prevents zombie accumulation
  • SA_RESTART flag resumes interrupted syscalls automatically

Example Usage:

./bin/myshell
> ls -l | grep .c | wc -l
> cat input.txt | sort > output.txt
> sleep 10 &

2. Thread-Safe Queue (src/queue/)

Design:

  • Dual-queue architecture (item queue + per-thread wait queue)
  • Single mutex protects both queues (simple critical section)
  • Per-consumer condition variables (eliminates thundering herd)
  • Lock-free atomic counter for throughput telemetry

API:

void initQueue(void);              // Initialize synchronization primitives
int enqueue(void *item);           // Add item (wakes waiting consumer if present)
void *dequeue(void);               // Remove item (blocks if empty)
size_t visited(void);              // Non-blocking throughput query
void destroyQueue(void);           // Cleanup

Synchronization Pattern:

  1. Consumer arrives first β†’ parks on unique cnd_t in wait queue
  2. Producer enqueues β†’ directly hands off item to waiting consumer
  3. No waiting consumers β†’ append to item queue
  4. Fast path: consumer grabs from item queue without blocking

Performance Notes:

  • memory_order_relaxed for atomic counter (no barriers needed for telemetry)
  • Avoids global condition variable broadcasts (O(1) wakeups)

πŸ§ͺ Testing Strategy

Automated Tests

# Run all tests
make test

# Memory leak check (requires Valgrind)
make debug
valgrind --leak-check=full ./bin/queue_test

# Thread safety check
valgrind --tool=helgrind ./bin/queue_test

Critical Edge Cases Tested

Component Test Case Status
Queue Concurrent enqueue/dequeue βœ… Covered
Queue Multiple producers, empty queue βœ… Covered
Queue Throughput validation βœ… Covered
Shell Zombie prevention (SIGCHLD) βœ… Manual test
Shell FD cleanup in pipelines βœ… Code review
Shell SIGINT delegation βœ… Manual test

See TESTING.md for comprehensive edge case analysis and testing philosophy.


πŸŽ“ Interview Preparation

30-Second Pitch

"I built a minimal shell and thread-safe queue in pure C11 to demonstrate low-level systems expertise. The shell handles multi-stage pipelines with proper signal semantics, while the queue achieves ~400K items/sec using per-thread condition variablesβ€”a pattern I saw in production databases. Both emphasize correct resource management and pragmatic design."

Top Technical Questions Covered

  1. Race condition prevention (mutex + per-thread condition variables)
  2. Signal handling semantics (SIGINT, SIGCHLD, SA_RESTART)
  3. Debugging deadlocks (GDB, Valgrind, lock ordering)
  4. Memory management (ownership rules, Valgrind verification)
  5. Performance trade-offs (mutex vs. lock-free, batch operations)

See TECHNICAL_ANALYSIS.md for in-depth Q&A and behavioral interview strategies.


πŸ” Code Quality

Static Analysis

  • clang-format: Consistent code style (.clang-format included)
  • Compiler warnings: Zero warnings with -Wall -Wextra -Werror
  • Valgrind: Memory leak and race condition verification

CI/CD Pipeline

GitHub Actions workflow (.github/workflows/ci.yml):

  1. Build verification (both legacy and new structure)
  2. Automated test execution
  3. Executable validation
  4. Code formatting check (clang-format)

CI Status


🐳 Docker Support

Multi-Stage Build

# Build stage: Compile with full toolchain
FROM gcc:11-bullseye AS builder
COPY . /build
RUN make clean && make all && make test

# Runtime stage: Minimal Debian with non-root user
FROM debian:bullseye-slim
COPY --from=builder /build/bin/* /app/
USER sysuser

Image Size: ~80MB (minimal runtime dependencies)


πŸ“š Documentation

All source files include Doxygen-style comments with @brief, @param, and @return annotations.


🎯 Production Gaps & Future Enhancements

Known Limitations (Intentional Simplifications)

Component Limitation Production Fix
Queue Unbounded capacity Add max size + backpressure
Queue Destroy during active use is unsafe Reference counting or shutdown flag
Shell No job control (fg/bg) Process groups with setpgid()
Shell Limited error propagation in pipelines Per-stage exit status tracking

Design Philosophy: This project demonstrates foundational systems knowledge. I prioritized correctness and clarity over feature completeness, showing I can build the core mechanisms before adding complexity.


πŸ›‘οΈ Security Considerations

  • Non-root Docker execution: Container runs as sysuser (UID 1000)
  • No shell injection vectors: Uses execvp() directly, no system() calls
  • Resource limits: Recommended to add ulimit for production (max FDs, max processes)

πŸ“– References and Learning Resources

POSIX Standards

C11 Threading

Debugging Tools


🀝 Contributing

This is a portfolio project, but feedback is welcome! If you spot a bug or have suggestions:

  1. Open an issue describing the problem
  2. Include steps to reproduce
  3. For code contributions, ensure make check passes

⚠️ Academic Integrity Notice

This repository is for portfolio and educational purposes only. If you are a student currently taking an Operating Systems course, copying this code violates academic integrity policies. I do not take responsibility for disciplinary actions against individuals who misuse this code.


πŸ“„ License

This project is licensed under the MIT License - see LICENSE file for details.


Built by Odeliya Charitonova Β· GitHub Β· LinkedIn

Computer Science student @ Tel Aviv University, School of CS & AI

About

C11 systems programming: Mini shell with multi-stage pipelines, signal handling, zombie prevention + thread-safe queue achieving ~400K items/sec with per-thread condition variables. Demonstrates POSIX signals, fork/exec/pipe, C11 threads, concurrency patterns, and production-ready code.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors