Reputation: 21
I wanted to implement memory management functions using C. The situation is like.. Total size of physical memory is 256mb
.
How can I allocate 128mb
to one process 64mb
to other process.
I want to implement best fit algorithm using freelist
& needs to do compaction.
Can anybody help me in this regard, or suggest any book for studying the same?
Upvotes: 2
Views: 166
Reputation: 22562
You can set the maximum amount of memory a process can use (Resident Set) with
ulimit -m 131072
for example to limit all forked processes from your shell to 128mb of maximum resident set.
Or in C via
#include <sys/time.h>
#include <sys/resource.h>
int setrlimit(int resource, const struct rlimit *rlim);
e.g.
struct rlimit rlim;
getrlimit(RLIMIT_RSS, &rlim);
rlim.rlim_cur = (128 << 20) / sysconf(_SC_PAGESIZE) // 128 MiB
setrlimit(RLIMIT_RSS, &rlim);
Upvotes: 2