Question: 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
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
