Os Lab Bca
Os Lab Bca
and termination.
#include <windows.h>
#include <stdio.h>
int main() {
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
0, // No creation flags
{
printf("Process creation failed (%d).\n", GetLastError());
return 1;
Sleep(5000);
if (!TerminateProcess(pi.hProcess, 0)) {
} else {
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return 0;
termination.
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
// Function to be executed by each thread
sleep(1);
pthread_exit(NULL);
int main() {
int status;
// Create thread 1
if (status != 0) {
exit(EXIT_FAILURE);
// Create thread 2
if (status != 0) {
exit(EXIT_FAILURE);
}
// Wait for thread 1 to finish
pthread_join(thread1, NULL);
pthread_join(thread2, NULL);
return 0;
Client
#include <windows.h>
#include <stdio.h>
int main() {
HANDLE hPipe;
char buffer[BUFFER_SIZE];
hPipe = CreateFile(
0, // Default attributes
);
if (hPipe == INVALID_HANDLE_VALUE) {
return 1;
printf("Connected to server!\n");
} else {
CloseHandle(hPipe);
Server
#include <windows.h>
#include <stdio.h>
int main() {
HANDLE hPipe;
char buffer[BUFFER_SIZE];
hPipe = CreateNamedPipe(
1, // Number of instances
0, // Default timeout
);
if (hPipe == INVALID_HANDLE_VALUE) {
printf("Failed to create named pipe. Error: %d\n", GetLastError());
return 1;
if (!connected) {
CloseHandle(hPipe);
return 1;
printf("Client connected!\n");
} else {
return 0;
4. Write a C program for Implementing Process Scheduling Algorithm. Also compute TAT and WT time
of each algorithm.
#include <stdio.h>
struct Process {
};
totalWaitingTime += p[i].waitingTime;
totalTurnAroundTime += p[i].turnAroundTime;
int main() {
int n;
scanf("%d", &n);
p[i].pid = i + 1;
scanf("%d", &p[i].burstTime);
calculateWaitingTime(p, n);
calculateTurnAroundTime(p, n);
printSchedulingInfo(p, n);
calculateAverageTimes(p, n);
return 0;
#include <stdio.h>
struct Process {
};
*a = *b;
*b = temp;
proc[0].turnAroundTime = proc[0].burstTime;
totalWaitTime += proc[i].waitTime;
totalTurnAroundTime += proc[i].turnAroundTime;
int main() {
int n;
scanf("%d", &n);
struct Process proc[n];
proc[i].id = i + 1; // Process ID
scanf("%d", &proc[i].burstTime);
sortByBurstTime(proc, n);
calculateTimes(proc, n);
displayProcesses(proc, n);
return 0;
#include <stdio.h>
struct Process {
};
*a = *b;
*b = temp;
proc[0].turnAroundTime = proc[0].burstTime;
totalWaitTime += proc[i].waitTime;
totalTurnAroundTime += proc[i].turnAroundTime;
int main() {
int n;
scanf("%d", &n);
struct Process proc[n];
proc[i].id = i + 1; // Process ID
scanf("%d", &proc[i].burstTime);
sortByBurstTime(proc, n);
calculateTimes(proc, n);
displayProcesses(proc, n);
return 0;
#include <stdio.h>
void findWaitingTimeRR(int processes[], int n, int bt[], int wt[], int quantum) {
rem_bt[i] = bt[i];
int t = 0; // Current time
while (1) {
int done = 1;
if (rem_bt[i] > 0) {
t += quantum;
rem_bt[i] -= quantum;
} else {
t += rem_bt[i];
rem_bt[i] = 0;
if (done == 1)
break;
void findTurnAroundTime(int processes[], int n, int bt[], int wt[], int tat[]) {
total_wt += wt[i];
total_tat += tat[i];
int main() {
int n, quantum;
scanf("%d", &n);
int processes[n], burst_time[n];
processes[i] = i + 1;
scanf("%d", &burst_time[i]);
scanf("%d", &quantum);
return 0;
e. Priority Scheduling
#include <stdio.h>
void findWaitingTimePriority(int processes[], int n, int bt[], int wt[], int priority[]) {
while (completed != n) {
highestPriority = priority[i];
idx = i;
currentTime += bt[idx];
completed++;
void findTurnAroundTimePriority(int processes[], int n, int bt[], int wt[], int tat[]) {
total_wt += wt[i];
total_tat += tat[i];
int main() {
int n;
scanf("%d", &n);
processes[i] = i + 1;
scanf("%d", &burst_time[i]);
scanf("%d", &priority[i]);
Programming.
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <semaphore.h>
// Producer function
int item;
buffer[in] = item;
pthread_exit(0);
// Consumer function
int item;
item = buffer[out];
pthread_exit(0);
int main() {
pthread_attr_init(&attr);
pthread_join(tid1, NULL);
pthread_join(tid2, NULL);
// Clean up
sem_destroy(&empty);
sem_destroy(&full);
pthread_mutex_destroy(&mutex);
return 0;