Saturday, September 30, 2023
Home 2022


Electronics Fifth Semester Notes Free Download

Nanoelectronics Notes


Similar Posts

Write a program that implements solution to Producer – Consumer problem using mutex and...

#include <stdio.h> #include <semaphore.h> #include <pthread.h> #include <stdlib.h> #include <time.h> pthread_mutex_t mutex; sem_t empty, full; int in=0, out=0, buffer[5]; void *producer(void *pno){ for(int i=0;i<5;i++){ sem_wait(&empty); pthread_mutex_lock(&mutex); int x = rand()%100; buffer[in]=x; in = (in+1)%5; printf("Producer %d has put %d in buffern",*((int*)pno), x); pthread_mutex_unlock(&mutex); sem_post(&full); } } void *consumer(void* cno){ for(int i=0;i<5;i++){ sem_wait(&full); pthread_mutex_lock(&mutex); int x = buffer[out]; out =...

program to perform the following tasks using system calls:

i) Parent process should create a child process ii) Both parent child processes should display their pid and parent’s pid; parent process should also its child’s pid iii) Load a new program into child...

Shell program to find the largest of three Numbers

#!/bin/bash echo "Enter three numbers (space seperated): " read a b c echo -n "Largest Number: " if [ $a -ge $b -a $b -ge $c ] then echo "$a" elif [ $b -ge $a -a $a -ge $c ] then echo "$b" else echo...

Program that implements solution to Readers-Writers problem using mutex and semaphores.

#include <stdio.h> #include <semaphore.h> #include <pthread.h> pthread_mutex_t mutex; sem_t wrt; int cnt=1, numreader=0; void *writer(void *wno){ sem_wait(&wrt); cnt = cnt*2; printf("Writer %d modified cnt to %dn", *((int*)wno), cnt); sem_post(&wrt); } void *reader(void* rno){ pthread_mutex_lock(&mutex); numreader++; if (numreader==1) sem_wait(&wrt); pthread_mutex_unlock(&mutex); printf("Reader %d read cnt as %dn", *((int*)rno), cnt); pthread_mutex_lock(&mutex); numreader--; if (numreader==0) sem_post(&wrt); pthread_mutex_unlock(&mutex); } void main(){ pthread_t write[10], read[10]; pthread_mutex_init(&mutex, NULL); sem_init(&wrt,0,1); int...