BCA / B.Tech 20 min read

Programmer Interface & File manipulation in Hindi

RK

लेखक Ratan Kumawat · संस्थापक, NotesMedia

प्रकाशित:

त्वरित सारांश और मुख्य बिंदु

  • • विषय फोकस: Operating System (OS) Notes in Hindi | ऑपरेटिंग सिस्टम नोट्स (BCA / B.Tech Syllabus)
  • • मुख्य विषय: Programmer Interface & File manipulation in Hindi - General Topics
  • • अवलोकन: Quick Answer: Linux Operating System mein Programmer Interface wah madhyam hai jiske zariye software applications operating system kernel aur underlying...
  • • मुख्य अवधारणाएं: Programmer interface file manipulation, APIs open read write Hindi, Close system calls,Programmer interface file manipulation, APIs open read write, Close system calls
Quick Answer: Linux Operating System mein Programmer Interface wah madhyam hai jiske zariye software applications operating system kernel aur underlying hardware se interact karti hain. Yah do levels par kaam karta hai: System Calls (jaise open(), read(), write(), fork()) jo low-level kernel services invoke karte hain, aur Standard C Libraries (glibc / POSIX APIs) jo high-level wrappers provide karti hain. File Manipulation ke antargat files ko create karna, read/write karna, file permissions (chmod) manage karna, aur Hard/Soft links banana shamil hai.

Linux Programmer Interface ka Concept aur Dual-Mode Architecture

Linux ek monolithic kernel operating system hai jo security aur stability ke liye CPU ko do distinct modes mein divide karta hai: User Mode (jahan aam user programs aur compilers run hote hain) aur Kernel Mode (jahan core OS kernel hardware resources ko control karta hai). Koi bhi user program direct physical hard drive ya RAM memory ko touch nahi kar sakta.

Jab kisi application ko file save karni hoti hai ya naya process banana hota hai, toh wah CPU ko ek software interrupt (trap instruction) bhej kar System Call execute karti hai. Linux system architecture samajhne ke liye aap hamara Kernel Based Operating System in Hindi aur shell commands ke liye Commands of Linux in Hindi note refer kar sakte hain.

Advertisement

Programmer Interface ke 4 Core Components

  1. System Calls (Kernel Interface): OS kernel ka direct door jiske through hardware I/O execute hota hai. Mukhya categories:
    • File Management: open(), read(), write(), close(), lseek(), unlink().
    • Process Control: fork(), exec(), wait(), exit().
    • Memory Management: brk(), mmap().
  2. Standard C Library (glibc): GNU C Library jo system calls ke upar user-friendly functions provide karti hai (jaise open() ke bajaye fopen() aur buffered I/O printf(), scanf()).
  3. POSIX API Standards: Portable Operating System Interface standards jo ensure karte hain ki Linux par likha gaya C code Unix ya macOS par bina badlav ke compile ho sake.
  4. Development & Toolchain Interface: GCC (GNU Compiler Collection), GDB (GNU Debugger), Make utilities, aur dynamic linkers (ld.so).

System Calls vs Library Functions Comparison

Comparison Parameter System Call (e.g. open, read, write) Library Function (e.g. fopen, fread, fwrite)
Execution Space Kernel Space (Privileged supervisor mode). User Space (Standard user program address space).
CPU Mode Switch Yes (User mode se Kernel mode mein switch hota hai; high overhead). Har call par nahi (data user-space buffer se mil jaye toh kernel call nahi hota; buffer khali/full hone par andar se system call hi hota hai).
Buffering Mechanism User-space buffering nahi hoti; har call seedha kernel ko jati hai (kernel apna page cache use karta hai). User-space stream buffer maintain karta hai (chunk-by-chunk reading).
Portability OS-dependent (POSIX/Unix-like systems par chalta hai, Windows par natively nahi). Highly Portable (ANSI C standard jo har OS par chalta hai).
Return Identifier Integer File Descriptor (jaise 0, 1, 2, 3...). FILE* stream structure pointer.

Complete Working C Program: Low-Level System Calls se File Manipulation

Niche diye gaye C program mein POSIX low-level system calls ka upyog karke file create, write aur read karke dikhaya gaya hai:

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>

int main() {
    char dataBuffer[100];
    const char *textPayload = "Welcome to NotesMedia Linux OS Guide!\n";

    // 1. File Create & Open karna (Write-only, Create if missing, Truncate old)
    // 0644 permission: Owner read/write, Group aur Others read-only
    int fileDescriptor = open("sample_output.txt", O_CREAT | O_WRONLY | O_TRUNC, 0644);
    if (fileDescriptor < 0) {
        perror("File open failed");
        exit(1);
    }

    // 2. File mein Data Write karna
    ssize_t bytesWritten = write(fileDescriptor, textPayload, strlen(textPayload));
    printf("%zd bytes written successfully.\n", bytesWritten);

    // 3. File descriptor close karna
    close(fileDescriptor);

    // 4. File ko dobara Read mode mein open karna
    fileDescriptor = open("sample_output.txt", O_RDONLY);
    if (fileDescriptor < 0) {
        perror("Read open failed");
        exit(1);
    }

    // 5. Bytes read karke screen par print karna
    ssize_t bytesRead = read(fileDescriptor, dataBuffer, sizeof(dataBuffer) - 1);
    if (bytesRead < 0) {
        perror("Read failed");
        exit(1);
    }
    dataBuffer[bytesRead] = '\0'; // Null-terminate string
    printf("Content read from file:\n%s", dataBuffer);

    // 6. Clean close
    close(fileDescriptor);
    return 0;
}

Output:

38 bytes written successfully.
Content read from file:
Welcome to NotesMedia Linux OS Guide!

Linux File Permissions: Representation aur chmod

Linux har file aur directory par 3 entity levels par security enforce karta hai: Owner (u), Group (g), aur Others (o). Har entity ke paas teen basic permissions hoti hain:

  • r (Read, Value = 4): File ki samagri padhne ki azaadi.
  • w (Write, Value = 2): File mein edit karne ya data append karne ki azaadi.
  • x (Execute, Value = 1): File ko binary program ya script ki tarah run karne ki azaadi.

Octal Permission Notation Matrix

Octal Code Permission String Effective Access Meaning
chmod 777 file -rwxrwxrwx Sabhi ke paas full access (read, write, execute) - Highly unsafe.
chmod 755 file -rwxr-xr-x Owner ko full access; Group aur Others kewal padh aur execute kar sakte hain (Standard for scripts/binaries).
chmod 644 file -rw-r--r-- Owner read-write; Group aur Others kewal read-only (Standard for regular text documents).
chmod 600 file -rw------- Kewal Owner read-write; baaki kisi ke liye no access (Standard for private SSH keys).
Advertisement

Linux Links: Hard Link vs Soft Link (Symlink) Comparison

Linux filesystem mein files disk par Blocks and Inodes in Hindi architecture ke zariye manage hoti hain. Links do alag tarike se kaam karte hain:

Comparison Parameter Hard Link (ln file link) Soft Link / Symbolic Link (ln -s file link)
Inode Number Original file ke sath same identical Inode number share karta hai. Apna ek naya independent Inode number rakhta hai.
Original File Delete hone par Data surakshit rehta hai; hard link se data access hota rahega jab tak link count > 0 hai. Link break ho jata hai (Dangling / Broken pointer ban jata hai).
Across File Systems Alag-alag disk partitions/filesystems ke paar create nahi ho sakta. Kisi bhi alag drive, partition ya network mount par link kar sakta hai.
Directories par Linking Directories par allow nahi hota (filesystem infinite loops se bachne ke liye). Directories aur folders par freely allow hota hai.

Filesystem hierarchy aur directory traversal ke deep rules ke liye hamara File System in Linux in Hindi note zaroor inspect karein.

Exam के लिए Important Questions

Short Questions

  1. Programmer Interface kya hai? Linux mein iska primary role batayein.
    Programmer Interface wah framework hai jo system calls aur libraries ke madhyam se application software ko OS kernel aur hardware resources se interact karne deta hai.
  2. File Descriptor kya hota hai? Linux ke 3 standard descriptors kaunse hain?
    File descriptor ek non-negative integer hai jo open file ko represent karta hai. Standard descriptors: 0 (Standard Input - stdin), 1 (Standard Output - stdout), aur 2 (Standard Error - stderr).
  3. Hard Link aur Soft Link mein kya mool antar hai?
    Hard link original file ka direct inode pointer share karta hai aur original delete hone par bhi data bachata hai, jabki Soft link kewal path string store karta hai aur original delete hone par break ho jata hai.
  4. chmod command mein 755 ka kya matlab hota hai?
    Owner ko 7 (4+2+1 = rwx), Group ko 5 (4+0+1 = r-x) aur Others ko 5 (4+0+1 = r-x) permissions assign hoti hain.

Long Questions

  1. Linux Programmer Interface kya hai? System Calls aur Library Functions ke beech internal functioning, context switching aur performance ke aadhar par antar samjhaiye.
  2. Linux File Manipulation ke mukhya system calls (open, read, write, close, lseek) ka complete C program ke sath varnan kijiye tatha file descriptors ka role samjhaiye.
  3. Linux File Security aur Permission model (rwx, octal notation, chown, chgrp) ka vistrit vishleshan karein tatha Hard Link aur Symbolic Link ki karyapranali spasht kijiye.

Frequently Asked Questions (FAQs)

Q1: fopen() aur open() mein se kiska use karna chahiye?
Ans: General file reading aur text formatting ke liye high-level fopen() (buffered I/O) use karna chahiye kyunki yah fast aur portable hai. Low-level device control, sockets ya non-blocking I/O ke liye direct system call open() use hota hai.

Q2: Linux mein 'Everything is a File' ka kya matlab hai?
Ans: Linux design philosophy ke anusar hardware devices (disks, keyboards), inter-process communication pipes, aur network sockets sabhi ko file descriptor ke roop mein treat kiya jata hai aur sabhi par wahi standard read() aur write() calls chalte hain.

Q3: lseek() system call ka kya prayog hai?
Ans: lseek(fd, offset, whence) open file ke read/write pointer (cursor position) ko aage-peeche move karne ke liye use hota hai jisse random access file processing sambhav hoti hai.

Q4: unlink() system call kya karta hai?
Ans: unlink() file ke hard link count ko 1 se kam karta hai. Jab link count 0 ho jata hai aur koi process use open nahi rakhe hoti, tab OS file ke disk blocks ko permanently delete karke free kar deta hai.

अक्सर पूछे जाने वाले प्रश्न (FAQs)

Quick Answer: Linux Operating System mein Programmer Interface wah madhyam hai jiske zariye software applications operating system kernel aur underlying hardware se interact karti hain.
Operating System (OS) Notes in Hindi | ऑपरेटिंग सिस्टम नोट्स के पाठ्यक्रम में Programmer Interface & File manipulation in Hindi एक महत्वपूर्ण अध्याय है। यह मुख्य सिद्धांतों, परीक्षा प्रश्नों और सूत्रों को समझने के लिए अत्यधिक आवश्यक है।
हाँ, NotesMedia पर आपको Programmer Interface & File manipulation in Hindi के महत्वपूर्ण प्रश्नोत्तर, हल किए गए उदाहरण और नोट्स बिल्कुल मुफ्त मिलेंगे। अधिक अभ्यास के लिए आप हमारा ऐप भी डाउनलोड कर सकते हैं।
Advertisement

In this Chapter

Programmer Interface & File manipulation in Hindi
Distributed System in Hindi
Real Time System in Hindi
System Calls in Hindi
System Program in Hindi
Structure of Operating System in Hindi
Layers Design of Structure in Hindi
Unix in Hindi
Virtual Machine in Hindi
Kernel-Based Operating System in Hindi
Process in Hindi – OS में Process क्या है
Interacting Processes in Hindi
Threads in Hindi
Fundamental of Schedulling in Hindi
Scheduling Criteria in Hindi
Long Medium Short Term Scheduling in Hindi
Scheduling Algorithms in Hindi
Structure of Concurrent System in Hindi
Critical Region in Hindi
Critical Section in Hindi
Inter process Communication in Hindi
Monitor in Hindi
Semaphore in OS in Hindi – Counting और Binary Semaphore
Semaphores Implementation & Uses in Hindi
Logical and Physical Address in Hindi
Swapping in Hindi
Contiguous Allocation in Hindi
Segmentation in Hindi
Paging in OS in Hindi – Paging और Segmentation
Paging with Segmentation in Hindi
kernel Memory Allocation in Hindi
Page Replacement Algorithms in Hindi
Virtual Memory in Hindi
Virtual Memory with demand Paging in Hindi
Deadlock & Characterization in Hindi
Methods for Handling Deadlocks in Hindi
Deadlock Thrashing in Hindi
Allocation of Frames in Hindi
Virtual Memory using Segmentation in Hindi
Interprocess Communication protocol in Hindi
Network Operating System in Hindi
Design Issues in Distributed File System in Hindi
Network Structure in Hindi
Structure Distributed System in Hindi
File System and Coordination in Hindi
Linux in Hindi
Commands of Linux in Hindi | लिनक्स के कमांड्स हिंदी में
Process control in Linux in Hindi
Linux Kernel & Signals in Hindi
File System in Linux in Hindi
block & inodes in Hindi
System Editor in Hindi
Character Transliteration in Hindi
ED in Hindi
Vi Editor & There Commands in Hindi
Shell Script in Hindi
Looping & Decision Making in Hindi
Variables & File name Expansion in Hindi
Array in Hindi OS
Sub Program in Hindi
C interface with Linux in Hindi
Simpel Shell Programs in Hindi
BCA Part-1 | Operating Systems | Semester-I | MDSU Exam Paper 2023 (Held in 2024)
What is Operating System (OS) in Hindi
Operating System (OS) All Important Questions and Answers in Hindi (MDSU)
BCA || Operating System 2025 Paper || MDSU Exam Paper
BCA | OS(Operating System) 2023 Paper | MDSU Exam Paper
Type of Operating System in Hindi
Goals of Operating System in Hindi
Operation of Operating system in Hindi
Resource Allocation & Functions in Hindi
class of Operating system in Hindi
Batch Processing in Hindi
Multi Processing in Hindi
Time Sharing in Hindi