0% found this document useful (0 votes)
4 views3 pages

API Level Program

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

API Level Program

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

PROGRAMMING ASSIGNMENT – 2 (API LEVEL) – 15 MARKS

1)File I/O System Calls – Log File Analyzer (Using open, read, write, lseek, close)

Write a C program using ONLY UNIX system calls to:

 Open a text file provided as a command-line argument


 Count the number of lines, words, and characters
 Store the result in an output file [Link]
 Use system calls: open(), read(), write(), close(), lseek()

Outcome: Demonstrates File I/O APIs (Module-3)

2)Process Creation & Exec – Command Execution Utility (Using fork, exec, wait)

Write a C program to:

 Accept a UNIX command from the user


 Create a child process using fork()
 Execute the command using execlp()
 Parent should wait for the child and display its exit status

Outcome: Demonstrates Process control APIs (Module-4)

3)Inter-Process Communication – PIPE Based Communication

Write a C program to:

 Create a pipe
 Parent writes a string into the pipe
 Child reads the string, converts it to uppercase, and displays it
 Use: pipe(), fork(), read(), write(), close()

Outcome: Demonstrates Pipes IPC (Module-4)

4)Shared Memory – Producer-Consumer (Using shmget, shmat, shmdt)

Write a C program where:

 Parent process creates shared memory


 Writes a message into the shared memory
 Child process reads the message from shared memory and prints it
 Use: shmget(), shmat(), shmdt(), fork()
Outcome: Demonstrates Shared Memory IPC (Module-4)

5)Signals – Event Handling (Using signal, alarm, pause)

Write a C program to:

 Handle SIGINT (Ctrl+C) and display a custom message instead of termination


 Use an alarm() to trigger a message every 5 seconds
 Use signal(), alarm(), pause()

Outcome: Demonstrates Signal handling APIs (Module-5)

6)File Locking – Concurrency Handling (Using fcntl)

Write a C program to:

 Open a file
 Apply a write lock using fcntl()
 Allow the user to enter text and append it
 Release the lock
 Show proper error handling

Outcome: Demonstrates File Locking & fcntl (Module-3)

7)Process Control – Orphan & Zombie Demo (fork, sleep, wait)

Write a program to demonstrate creation of:

 Zombie Process
 Orphan Process

Explain using ps output.

8)Multi-Pipe Communication – Two Pipes for Full Duplex

Parent sends message → Child


Child modifies → sends back to Parent
Use two pipes.

9)File Operations – Directory Traversal using opendir/readdir

Write a program to list all files in a directory using:


opendir(), readdir(), closedir()
Filter only:

 .txt
 .c
 .sh files

10) Message Queues – Priority Message Sender

Write a program using System V message queues to:

 Send 3 messages with different priorities


 Receiver should print priority + message

Use: msgget(), msgsnd(), msgrcv()

11) Daemon Process – Background Logger

Write a program to:

 Create a daemon
 Log system time to [Link] every 10 sec
 Use fork(), setsid(), chdir(), umask()

12) Named Pipes FIFO – Chat Between Two Processes

Create two programs:

 writer.c
 reader.c
Communicate using FIFO: mkfifo(), open(), read(), write()

You might also like