Source Code ASCII Format

Total Page:16

File Type:pdf, Size:1020Kb

Source Code ASCII Format

Unix-Linux 1

Source code – ASCII format Binary code – runable binary format Object code – special intermediate code

Library (archive) Files  /usr/lib  /usr/local/lib

 Library Functions -- Runtime Library Procedures o Static Libraries  collections stored in object code to be used during linking phase

o Shared Object Libraries  relocatable objects to be shared by more than one process

o library file prefix – lib o library file extension -- .a

 Unix archive utility – ar  used to create libraries  modify libraries  extract members from a library  insert members into an existing library

Unix Manual Appendix A  Synopsis Section o List of the required “include” files, function prototypes, external variables, etc. e.g., $man perror  #include void perror(const char *s) #include const char *sys_errlist[ ]; Int sys_nerr; Managing Failure – see text

Process Memory  Text Segment  Data Segment  Stack Segment  u-Area Process Memory Addresses The addresses of the external variables  etext  edata  end correspond respectively to the first valid address above the segments  text  initialized data  unutilized data

Creating a Process  Startup – kernel BSD Unix Solaris o swapper pid 0 sched or fsflush o init pid 1 init o pagedaemon pid 2 pageout  User – children of init, i.e., pid 1

Process Environment  Process Group ID  parent is process group leader  parent pid == process group pid o descendents of the parent are members of the group o signals to process group  getpgpid( )  returns process group pid to the calling member of the group  setpgpid(pgpid)  changes process group to the specified group-pid, i.e., pgpid  stpgpid(0)  calling process becomes the group leader

Permissions $ls –l  displays permission numbers of all files listed $ls .*  displays all hidden files in current directory e.g., .exrc  startup info for vi :set numbers  files r w x  directories o r  display o w  files/links can be inserted or deleted o x  directory can be traversed, i.e., files listed in the directory can be accessed creation mask  executable files 777  directories 777  text files 666

umask  default – system administrator – 022  .login or .profile file o $umask nnn where nnn is the  new umask value  new umask value XOR creation mask value  the desired new permission number

 e.g., to obtain permission numbers of 700 for all new text files, the umask value should be set to 166  e.g., to obtain permission numbers of 700 for all new  executable files  directories the umask value should be set to 077

Privacy  create new files, directories, executable files  check the permissions granted  after creation, use chmod( ) to change the mode to the desired setting

Real User & & ID’s Effective Group

real user ID (UID) user real group ID (GID)  maps to group names stored in /etc/group maximum(UID, GID) found in the defined constant maxid located in file File Systems

User Space

Kernel Space u-area u-area fd fd

System System File Inode Table Table System Calls  status  stat data structure o stat o lstat o fstat  change mode o chmode – char * reference o fchmod – integer file descriptor number  umask o returns old umask value o which, if saved, can be used to restore the previous setting  getcwd -- returns a pointer to the current working directory pathname  chdir – change directory o no argument  returns to the users home directory o /  root directory o ../  parent directory o ./comp322 subdirectory 322

Resource Limits  Resources o cputime o filesize o datasize – data+stack segment size o stacksize -- stack segment size o coredumpsize – core dump file size o descriptors – number of file descriptors

 $limit  soft limits – limits that can be changed by the user  $limit –h  hard limits – limits that can only be increased by the superuser  ulimit  getrlimit  setrlimit  sysconfig

Signaling Processes  event requiring attention  signal  signal – software generated  generated by o hardware  attempt to address space outside its own address space  divide by zero o kernel – notifying process that an I/O device is available o other processes – child process notifying parent process that it is terminating o user – keyboard signal  quit  interrupt  stop signal Potential Process Actions  perform the system-specified default action a) notify parent of termination b) generate a core file – current memory image c) terminate  ignore the signal a) cannot ignore SIG-STOP (23) b) cannot ignore SIGKILL (9)  catch the signal a) invoke a special signal handling routine b) after execution of the routine, the process, if appropriate, resumes where it left off c) exceptions o cannot catch SIG-STOP (23) o cannot catch SIGKILL (9)

Command Line Values void main(int argc, char *argv[ ]) { for( ; *argv; ++argv) printf(“%s\n”, *argv); //new versions of Unix for(int i = 0; i < argc; i++) printf(“%s\n”, *argv); // any version of Unix }

$a.out this is a test

argc argv “a.out “this” “is” “a” “test”

Ξ (null) getopt( ) – see textbook Environmental Variables

 $man –s5 environ  detailed description of common environmental variables  char *getenv( );

 int putenv(char *string);  environmental variables are stored in Process Memory o Process Memory is fixed in size o environmental variables can be modified by the process but not expanded

 changing environmental variables by o adding new variables o modifying variables in such a way that it requires additional storage space is discouraged unless one investigates the ramifications very carefully!

 addresses associated with environmental variables are changed when a new environmental variable is added  child processes inherit a copy of the environmental variables from the parent

Recommended publications