Lecture 4: Process Memory Layout
Review: Unix File Access Control Subject Users(owner, group, others) Object Directory/File Actions read write execute Each file has associated with it a set of access permissions indicating, for each of three classes of principals, what sorts of operations on the file are allowed. The three classes are the owner of the file, known as user, the group owner of the file, known simply as group, and everyone else, known as others. The operations are grouped into the classes read, write, and execute, with their obvious meanings. The access permissions apply to directories as well as to ordinary files, though the meaning of execute for directories is not quite so obvious: one must have execute permission for a directory file in order to follow a path through it. The system, when checking permissions, first determines the smallest class of principals the requester belongs to: user (smallest), group, or others (largest). It then, within the chosen class, checks for appropriate permissions. Copyright © 2002 Thomas W. Doeppner. All rights reserved.
System Calls For File Management
System Calls For Directory Management
System Calls For Miscellaneous Tasks
In this lecture Process memory layout
Linux process memory layout Stack Heap Static data Text (program) Address space or core image
Linux process memory layout Stack: Automatically allocated and deallocated Local variables, parameters Heap: Manually allocated (malloc) and deallocated (free) Dynamic sized data structures Static data Global variables Text Program
An example int g; int main() { int a; int*b = (int*)malloc(sizeof(int) *2); return 0; }
An example Stack, a Stack, b Heap, b_content Static data, g Text (program)
Multiple processes in memory Unused Stack Heap Static data Text (program) Process 1 Stack Heap Static data Text (program) Unused Process 2
Function Call int main() { int a; a=f(); } int f() { int a,b; return (a*b); }
Stack Frame arguments return address stack frame pointer Heap Static data Text (program) arguments return address stack frame pointer local variables To previous stack frame pointer To the point at which this function was called
Function Call Hierarchy int f() { int a; a=10; return (a*g()); } int g() { int a; a=100; return (a); } int main() { int a; a=f(); }
Fibonacci Numbers int fib (int n) { if (n < 0) return 0; return (fib(n-1)+fib(n-2)); } fib (3): how many stack frames?
Memory leakage Stack, a Stack, b (pointer) Heap, b_content Static data, g Text (program)
Garbage Collection No need to explicitly deallocate memory i.e. no need for free() or equivalent No memory leaks Automatic Garbage Collection http://sleibowitz.home.att.net/CPP_Java/AGC.html A key feature of Java is its garbage-collected heap http://www.javaworld.com/javaworld/jw-08-1996/jw-08-gc.html
Summarizing Process memory layout Stack frame for function calls Stack Heap Static data Text Stack frame for function calls