{"id":23061780,"url":"https://github.com/hammadhttps/linux-system-calls","last_synced_at":"2025-04-03T07:19:50.525Z","repository":{"id":258702923,"uuid":"872477436","full_name":"hammadhttps/linux-system-calls","owner":"hammadhttps","description":"This repository features code examples demonstrating key Unix/Linux system calls such as open(), read(), write(), fork(), dup(), dup2(), pipes, shared memory, and FIFOs. It also includes practical usage of various Linux commands. Ideal for those exploring process management, file handling, IPC mechanisms, and low-level system programming.","archived":false,"fork":false,"pushed_at":"2024-10-20T14:19:56.000Z","size":89,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-08T21:11:18.448Z","etag":null,"topics":["client-server","commandline","fifo","inter-process-communication","linux","operating-systems","shell","systemcalls"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hammadhttps.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-14T14:00:05.000Z","updated_at":"2024-12-06T00:15:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"4eb33352-aadc-42b6-bca1-c762ae05f80d","html_url":"https://github.com/hammadhttps/linux-system-calls","commit_stats":null,"previous_names":["hammadulhassan5812/linux-system-calls","hammadhttps/linux-system-calls"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hammadhttps%2Flinux-system-calls","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hammadhttps%2Flinux-system-calls/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hammadhttps%2Flinux-system-calls/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hammadhttps%2Flinux-system-calls/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hammadhttps","download_url":"https://codeload.github.com/hammadhttps/linux-system-calls/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246952278,"owners_count":20859813,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["client-server","commandline","fifo","inter-process-communication","linux","operating-systems","shell","systemcalls"],"created_at":"2024-12-16T03:18:30.148Z","updated_at":"2025-04-03T07:19:50.495Z","avatar_url":"https://github.com/hammadhttps.png","language":"C","readme":"# Linux-System-Calls\nThis repository features code examples demonstrating key Unix/Linux system calls such as open(), read(), write(), fork(), dup(), dup2(), pipes, shared memory, and FIFOs. It also includes practical usage of various Linux commands. Ideal for those exploring process management, file handling, IPC mechanisms, and low-level system programming.\n\n\n1-**Custom Shell - Command Line Interpreter**\nThis project implements a simple command-line interpreter in C, designed to execute common Linux commands. The shell supports:\nCommand execution with tokenization (e.g., ls, cp, cd, pwd, mv, mkdir, rmdir, rm, touch, grep).\nContinuous user interaction with child processes created using system calls like execvp or execlp.\nThe program runs until the user types exit.\n\n\n**2-Automated Production Line Process Management**\nThis C program simulates process management for a company's automated production line, consisting of four stages: Material Preparation, Assembly, Quality Check, and Packaging.\n\n**Key Features**:\nStage Execution: Each stage runs in a separate process and simulates work by sleeping for a few seconds.\nProcess Coordination: Ensures each stage completes before the next starts using waitpid(). In case of failure, a stage is retried up to two times.\nError Handling: Logs issues and terminates the line if a stage fails after multiple attempts.\nCompletion Report: Provides a summary of successful completions and retry attempts.\nThe program makes use of process management techniques like fork(), waitpid(), exit(), and signal handling, while simulating random failures with a 30% chance per stage.\n\n**3-Secure Data Transformation**\nThis C/C++ program securely transforms critical data from the compromised file classified_data.txt. It allows for safe analysis by either decrypting the data or redacting sensitive information.\n\n**Key Features:**\nDecryption: Uses a simple Caesar cipher to shift each character backward by one (if a decryption key is available).\nRedaction: Replaces sensitive information like SSNs (e.g., \"123-45-6789\") with [REDACTED].\nParent-Child Process Interaction: The transformation is securely handled by a child process, ensuring sensitive data remains protected.\nFile I/O Handling: The parent process manages file writing and generates a summary report.\nDecryption Example: Input \"Uifsf jt b tfdsfu npofz\" becomes \"There is a secret money\".\nRedaction Example: Input \"SSN: 123-45-6789\" becomes \"SSN: [REDACTED]\".\n\n\n**4-BattleShip Game**\nThis is a C++ implementation of the classic Battleship game, where two players (Player 1 and Player 2) play on separate 5x5 grids to guess and sink each other's ships. The game uses pipes for communication between two processes representing the players, ensuring turn-based gameplay with real-time interaction.\n\n**Game Rules:**\nEach player has a 5x5 grid, with 3 ships placed at the beginning of the game.\n\n**Ship Sizes:**\nShip 1: 2 spaces\nShip 2: 3 spaces\nShip 3: 4 spaces\nShips can be placed horizontally or vertically on the grid, and overlapping ships are not allowed.\nPlayers take turns to guess the location of their opponent's ships by providing row and column coordinates.\nEach guess results in either a Hit (H) or Miss (M).\nThe goal is to sink all the opponent's ships by guessing their locations.\nThe game ends when one player successfully sinks all three ships of the opponent.\n\n**Communication Between Players:**\nThe game uses two pipes for communication between Player 1 and Player 2:\nPipe 1: Player 1 sends their guesses to Player 2.\nPipe 2: Player 2 sends their guesses to Player 1.\nAfter each guess, the player will wait for the response from the other player (either H for Hit or M for Miss), and then proceed to their next turn.\n\n**Features:**\nTurn-Based Gameplay: Each player must wait for the other player's move before taking their next turn.\nHit/Miss Feedback: Players are informed whether their guess hits or misses the opponent's ships.\nError Handling: Proper handling of communication failures through pipes ensures smooth gameplay.\n\n**Game Flow:**\nPlayer 1's Turn:\nPlace ships on the grid.\nSend a guess (row, col) through Pipe 1.\nWait for a response (Hit/Miss).\nIf all Player 2's ships are hit, Player 1 wins and the game ends.\nPlayer 2's Turn:\nPlace ships on the grid.\nReceive Player 1's guess from Pipe 1.\nCheck for Hit/Miss and respond through Pipe 1.\nSend their own guess (row, col) through Pipe 2.\nWait for Player 1's response (Hit/Miss).\nIf all Player 1's ships are hit, Player 2 wins and the game ends.\n\n**Requirements:**\nPipes: For bidirectional communication between Player 1 and Player 2.\nfork(): To create separate processes for Player 1 and Player 2.\nwaitpid(): To ensure synchronization between player moves and prevent multiple guesses by the same player in a row.\nError Handling: For managing errors in pipe communication, ensuring the game does not crash unexpectedly.\nHow to Compile and Run:\n\n**Compile the game:**\ng++ battleship.cpp -o battleship\nRun the game:\n./battleship\n\n\n\n\n**5-File Descriptor Duplication and Redirection in C++**\nThis C++ program demonstrates file input/output redirection using file descriptor duplication and redirection techniques (dup() and dup2()). The program reads data from an input file, processes it, and redirects standard output and standard error to specified output files.\n\n**Overview:**\nInput File: Reads data from a specified input file.\nOutput File: Redirects standard output (stdout) to a specified output file.\nError File: Redirects standard error (stderr) to a specified error file.\n\n**Functionality:**\n\n**File Handling:**\nThe program accepts three command-line arguments:\nInput File: The file to read data from (e.g., input.txt).\nOutput File: The file to redirect standard output to (e.g., output.txt).\nError File: The file to redirect standard error to (e.g., error.txt).\nIt opens the input file for reading and the output/error files for writing.\n\n**Duplicating and Redirecting stdout and stderr:**\nThe original stdout and stderr file descriptors are saved using dup().\ndup2() is used to redirect stdout to the output file and stderr to the error file.\n\n**Processing Input:**\nThe program reads lines from the input file and processes the data:\nFor each valid number, it outputs a processed number (e.g., performing operations like multiplication).\nIt handles invalid numbers (e.g., non-numeric values) and division by zero, outputting error messages to stderr (which is redirected).\n\n**Restoring Original File Descriptors:**\nAfter processing, the original stdout and stderr are restored using dup() and dup2().\nA confirmation message is printed to the console indicating that the file descriptors have been restored.\n\n**Error Handling:**\nThe program handles invalid file paths for the input, output, and error files.\nIf the input file cannot be opened, an appropriate error message is output using stderr (without redirection).\n\n\n\n**6-Complex Number Array Processing in C**\nThis C program demonstrates the use of **shared memory** to perform various operations on an array of complex numbers using multiple child processes. The program computes the complex conjugate, magnitude, and sum of the provided complex numbers.\n\n\n**7-Multi-Stage File Processing in C**\nThis C program implements a multi-stage file processing system that utilizes named pipes (FIFOs) for inter-process communication. The program reads an array of integers from a file and performs multiple transformations across different stages.\n\n\n**Compile the program:**\ngcc multi_stage_processing.c -o multi_stage_processing\n\n\n**Run the program with command-line arguments:**\n./multi_stage_processing input.txt 20\n\n\n\n**8-FIFO Pipes Chat System**\nThis project implements a simple chat system using FIFO pipes in C, enabling communication between two unrelated processes: one for sending messages (sender.c) and another for receiving them (receiver.c). The system uses a named pipe (FIFO) to facilitate message exchange.\n\n**Files**\n**sender.c**: This program takes user input (strings) continuously and sends the messages through the FIFO pipe.\n**receiver.c**: This program reads the messages from the FIFO pipe and displays them on the screen.\nSetup \u0026 Execution\nCompile the programs:\ngcc -o sender sender.c\ngcc -o receiver receiver.c\n\nCreate the FIFO: Before running the programs, create a named pipe (FIFO):\nmkfifo chatpipe\nRun the Receiver: Start the receiver first, as it will wait for messages:\n\n./receiver\nRun the Sender: Open a new terminal and run the sender:\n\n./sender\nHow It Works\nThe sender program continuously takes user input and writes it into the chatpipe FIFO.\nThe receiver program reads the data from chatpipe and displays it on the screen.\nImportant Notes\nEnsure both programs have access to the named pipe (chatpipe).\nThe receiver should be started first to avoid blocking the sender.\nCleanup\nAfter using the programs, you can remove the FIFO:\n\nCopy code\nrm chatpipe\nConclusion\nThis simple chat system demonstrates inter-process communication (IPC) using named pipes (FIFO) in C for unrelated processes.\n\n\n**Client-Server Calculation System**\nThis project implements a simple client-server system using FIFO pipes for inter-process communication. The client sends a mathematical expression to the server, the server evaluates the expression, and the result is returned to the client.\n\n**Features**\nClient: Takes a mathematical expression as input (e.g., 5 + 3) and sends it to the server via a FIFO pipe.\nServer: Reads the expression from the client, evaluates it, and sends the result back to the client using another FIFO pipe.\nMultiple Requests: Both processes handle multiple requests and responses efficiently.\n\n**Setup and Usage**\nCompile the Client and Server Programs:\ngcc client.c -o client\ngcc server.c -o server\n\nCreate FIFO Pipes:\nmkfifo fifo_client_to_server\nmkfifo fifo_server_to_client\n\n\nRun the Server:\n./server\n\n\nRun the Client:\n./client\n\n![04bdc3a9-258f-4109-9ae4-5cdee492234e](https://github.com/user-attachments/assets/2af973a7-485a-4556-b499-661ab86f6490)\n\n\n\n\n\n\n\n\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhammadhttps%2Flinux-system-calls","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhammadhttps%2Flinux-system-calls","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhammadhttps%2Flinux-system-calls/lists"}