System Files and Process Environment Password file Group file System identification Time Process environment.

Slides:



Advertisements
Similar presentations
Dynamic memory allocation
Advertisements

Dynamic Memory Allocation in C.  What is Memory What is Memory  Memory Allocation in C Memory Allocation in C  Difference b\w static memory allocation.
Chapter 7 Process Environment Chien-Chung Shen CIS, UD
CS1061: C Programming Lecture 21: Dynamic Memory Allocation and Variations on struct A. O’Riordan, 2004, 2007 updated.
Growing Arrays in C Language. When to Use Do not use Growing Sorted Array –O(n 2 ) Operation –Avoid when n is large Use Keep track of a variable –Few.
1 Memory Allocation Professor Jennifer Rexford COS 217.
User-Level Memory Management in Linux Programming
Agenda  Review: pointer & array  Relationship between pointer & array  Dynamic memory allocation.
More Pointers Write a program that: –Calls a function to input an integer value –The above function calls another function that will double the input value.
[Unix Programming] Process Basic Young-Ju, Han
Pointer applications. Arrays and pointers Name of an array is a pointer constant to the first element whose value cannot be changed Address and name refer.
Week 7 - Friday.  What did we talk about last time?  Allocating 2D arrays.
Memory allocation CSE 2451 Matt Boggus. sizeof The sizeof unary operator will return the number of bytes reserved for a variable or data type. Determine:
Discussion: Week 3/26. Structs: Used to hold associated data together Used to group together different types of variables under the same name struct Telephone{
CSCE Systems Programming Lecture 05 - Processors, Memory CSCE 510 Jan 23, 2013.
The Environment of a UNIX Process. Introduction How is main() called? How are arguments passed? Memory layout? Memory allocation? Environment variables.
Informática II Prof. Dr. Gustavo Patiño MJ
1 Day 03 Introduction to C. 2 Memory layout and addresses r s int x = 5, y = 10; float f = 12.5, g = 9.8; char c = ‘r’, d = ‘s’;
ECE 353: Lab C Pointers and Structs. Basics A pointer holds an address to some variable Notation: – Dereferencing operator: * int *x is a declaration.
Process Control Hua LiSystems ProgrammingCS2690Process Control Page 1 of 41.
1 Homework / Exam HW7 due class 25 Exam 3 - class 26 –Open Book, Open Notes –Covers up through end of K&R 7 –and Appendix B Standard Library –Plus UNIX.
Unix Process Environment. main Function A C program starts execution with a function called main. The prototype for the main function is: int main (int.
Operating Systems Recitation 11, June 9-10, 2002.
1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation –The new operator –The delete operator –Dynamic.
Advanced Programming in the UNIX Environment Hop Lee.
1 Procedural Concept The main program coordinates calls to procedures and hands over appropriate data as parameters.
Week 8 - Friday.  What did we talk about last time?  String to int conversions  Users and groups  Password files.
Week 9 Part 2 Kyle Dewey. Overview Announcement More with structs and memory Assertions Exam #2 Course review.
Class 2 CSI2172
1 C - Memory Simple Types Arrays Pointers Pointer to Pointer Multi-dimensional Arrays Dynamic Memory Allocation.
Pointers and Arrays Beyond Chapter Pointers and Arrays What are the real differences? Pointer Holds the address of a variable Can be pointed.
Chapter 0.2 – Pointers and Memory. Type Specifiers  const  may be initialised but not used in any subsequent assignment  common and useful  volatile.
1 Logging in to a UNIX System init ( Process ID 1 created by the kernel at bootstrap ) spawns getty for every terminal device invokes our login shell terminal.
UNIX UTILITY PACKAGE Shell Simulator Added Shell Commands File System Explorer ( LNC ) System Information Process Tree Viewer.
Process Control Process identifiers Process creation fork and vfork wait and waitpid Race conditions exec functions system function.
CPS4200 Unix Systems Programming Chapter 2. Programs, Processes and Threads A program is a prepared sequence of instructions to accomplish a defined task.
TELE 402 Lecture 6: Name and address conversions 1 Overview Last Lecture –Socket Options and elementary UDP sockets This Lecture –Name and address conversions.
Operating Systems Process Creation
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo1 Timers and Clocks.
+ Dynamic memory allocation. + Introduction We often face situations in programming where the data is dynamics in nature. Consider a list of customers.
Interacting with Unix. Getting the Process ID u Synopsis #include pid_t getpid(void); u Example: #include int main(){ pid_t n = getpid(); printf("Process.
1/15/2016Course material created by D. Woit 1 CPS 393 Introduction to Unix and C START OF WEEK 11 (C-5)
1 System Programming Chapter 6. 2 Administration Misc. The mid-term will be held on April 26, 2006 in class. It will cover Chapters 1 to 6. MP2 is due.
S -1 Processes. S -2 wait and waitpid (11.2) Recall from a previous slide: pid_t wait( int *status ) wait() can: (a) block; (b) return with status; (c)
CSCE Systems Programming Lecture 06 - C++/Java  C, Memory CSCE 510 Jan 23, 2013.
Dynamic Memory Management & Static Class Members Lecture No 7 Object Oriented Programming COMSATS Institute of Information Technology.
Week 9 - Wednesday.  What did we talk about last time?  structs.
Advanced Programming in the UNIX Environment Hop Lee.
“Success consists of going from failure to failure without loss of enthusiasm.” Winston Churchill.
Chapter 7 Process Environment Chien-Chung Shen CIS/UD
Computer Science 516 Addressing Modes. Addressing modes are how our programs get to data Multiple addressing modes created for specific uses Function.
CHAPTER 6. SYSTEM DATA FILES AND INFORMATION System Programming 本份投影片大量參考熊博安教授的系統程式投影片 羅習五 國立中正大學資訊工程學系
Linux/UNIX Programming APUE (Process Control) 문양세 강원대학교 IT 대학 컴퓨터과학전공.
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo
Stack and Heap Memory Stack resident variables include:
Day 03 Introduction to C.
Linux Processes & Threads
Day 03 Introduction to C.
UNIX PROCESSES.
Operating Systems 15 - security
Pointers, Dynamic Data, and Reference Types
Memory Allocation CS 217.
EECE.2160 ECE Application Programming
Dynamic Memory Allocation (and Multi-Dimensional Arrays)
The Environment of Unix Process
Pointers and Arrays Beyond Chapter 16
C Programming Lecture-8 Pointers and Memory Management
Dynamic Memory – A Review
Pointers, Dynamic Data, and Reference Types
Week 7 - Friday CS222.
Presentation transcript:

System Files and Process Environment Password file Group file System identification Time Process environment

Password File doej:x:293:105:John Doe:/home/doej:/bin/sh passwd struct char *pw_name char *pw_passwd uid_t pw_uid gid_t pw_gid char *pw_gecos char *pw_dir char *pw_shell

Password File struct passwd *getpwnam(const char *name); Gets a pointer to a passwd struct based on the login name struct passwd *getpwuid(uid_t uid); Gets a pointer to a passwd struct based on the user ID Both return a pointer if OK and NULL on error Requires

Shadow Passwords Encrypted passwords kept in separate file /etc/shadow Minimally contains the username and encrypted password Password field of /etc/passwd replaced with ‘x’ Only root can open and read the shadow file

Group File Located in /etc/group struct group char *gr_name char *gr_passwd int gr_gid char **gr_mem

Group File struct group *getgrnam(const char *name); Gets a pointer to a group struct based on group name struct group *getgrgid(gid_t gid); Gets a pointer to a group struct based on group ID

System Identification int uname(struct utsname *buf); Stores system information in the structure pointed to by buf char sysname[] char nodename[] char release[] car version[] char machine[]

System Identification int gethostname(char *name, size_t len); Copies hostname into the buffer of size len pointed to by name. If the buffer is not large enough, hostname is truncated and may not be null terminated Returns 0 on success or -1 on error

Date and Time time_t time(time_t *t); Stores an instance of the time_t at the location pointed to by t Holds both time and date Returns a time_t value if ok, -1 on error struct tm *gmtime(const time_t *timep); struct tm *localtime(const time_t *timep); These functions break down a raw time_t into a struct tm representation

Date and Time struct tm tm_sec0-60 tm_min0-59 tm_hour0-23 tm_mday1-31 tm_mon0-11 tm_year tm_wday0-6 tm_yday0-365 tm_isdst 0

Date and Time More functions See man pages for gettimeofday settimeofday mktime asctime ctime strftime See page 174 fig 6.8

Process Environment main function When a C program is started by the kernel, a start up routine is called before main is called. Added in by the linker automatically Start up routine is given as the starting address of the executable program

Process Termination Normal Return from main A call to exit A call to _exit or _Exit Abnormal A call to abort (SIGABRT) Receiving a kill signal (SIGTERM)

Exit Functions _exit and _Exit functions return to Kernel immediately exit function performs cleanup and then returns to Kernel Start up routine returns to the Kernel the value returned from main exit(main(argc, argv));

Environment List Name=value pairs Passed to every process Global variable environ. Pointer to an array of strings Functions char *getenv(const char *name); int putenv(char *string); int setenv(const char *name, const char *value, int overwrite);

Memory Layout of a C Program Text segment – read only machine instructions Initialized data segment Uninitialized data segment Stack Heap See fig 7.6 on page 188 size command can be used to find the sizes of the various sections

Allocate and Free Memory void *calloc(size_t nmemb, size_t size); void *malloc(size_t size); void *realloc(void *ptr, size_t size); void free(void *ptr); calloc clears (sets to zero) the memory it allocates realloc changes the size of the allocated memory (usually to allocate more)