-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpidmanager.c
More file actions
61 lines (48 loc) · 969 Bytes
/
pidmanager.c
File metadata and controls
61 lines (48 loc) · 969 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <stdio.h>
#define MINPID 300
#define MAXPID 5000
#define PID_LEN MAXPID - MINPID + 1
int PIDbitmap[MAXPID - MINPID];
int allocate_map()
{
for (int i = 0; i < PID_LEN; i++)
{
PIDbitmap[i] = 0;
}
return 1;
}
int allocate_pid()
{
for (int i = 0; i < PID_LEN; i++)
{
if(PIDbitmap[i] == 0)
{
PIDbitmap[i] = 1; //CREATED PID
int createdPID=i+MINPID;
printf("Created PID is :%d\n",createdPID);
return createdPID;
}
}
printf("Cannot create PID Slots are full");
return 1;
}
void release_pid(int pid)
{
if(pid>MAXPID || pid<MINPID)
{
printf("This PID does not exist in manager. Returning...");
return;
}
else
{
PIDbitmap[pid-MINPID] = 0;
printf("Released PID no :%d\n",pid);
}
}
int main()
{
int pid;
allocate_map();
pid = allocate_pid();
release_pid(pid);
}