1 / 17

System Files and Process Environment

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.

quilla
Download Presentation

System Files and Process Environment

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 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

  3. 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 <pwd.h>

  4. 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

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

  6. 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

  7. 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[]

  8. 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

  9. 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

  10. Date and Time • struct tm • tm_sec 0-60 • tm_min 0-59 • tm_hour 0-23 • tm_mday 1-31 • tm_mon 0-11 • tm_year • tm_wday 0-6 • tm_yday 0-365 • tm_isdst <0, 0, >0

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

  12. 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

  13. 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)

  14. 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 mainexit(main(argc, argv));

  15. 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);

  16. 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

  17. 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)

More Related