Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please change the following code to python form. #include #include #define MIN_PID 300 #define MAX_PID 5000 #define TRUE 1 #define FALSE 0 struct PidTable{ int
Please change the following code to python form.
#include#include #define MIN_PID 300 #define MAX_PID 5000 #define TRUE 1 #define FALSE 0 struct PidTable{ int PID; int isAvailable; }*pId; int allocate_map(){ int i; pId=(struct PidTable *)calloc((MAX_PID-MIN_PID+1),sizeof(struct PidTable)); if(pId==NULL) return -1; pId[0].PID=MIN_PID; pId[0].isAvailable=TRUE; for( i=1;i return 1; } int allocate_pid(){ int i ; for( i=0;i if(pId[i].isAvailable==TRUE){ pId[i].isAvailable=FALSE; return pId[i].PID; } } if(i==MAX_PID-MIN_PID+1) return -1; } void release_pid(int pid){ pId[pid-MIN_PID].isAvailable=TRUE; } int main(){ int pid; allocate_map(); if((pid=allocate_pid())!=-1); printf("New Process Allocated Pid= %d ",pid); if((pid=allocate_pid())!=-1); printf("New Process Allocated Pid= %d ",pid); if((pid=allocate_pid())!=-1); printf("New Process Allocated Pid= %d ",pid); if((pid=allocate_pid())!=-1); printf("New Process Allocated Pid= %d ",pid); printf("Process %d now Releasing ",pid); release_pid(pid); if((pid=allocate_pid())!=-1); printf("New Process Allocated Pid= %d ",pid); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started