Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Processes I<br />
! Example<br />
int debug = 1; /* initialised read-write variable */<br />
char *progname;<br />
/* uninitialised read-write variable*/<br />
main (argc, argv)<br />
int argc; char *argv[];<br />
{<br />
int i; /* automatic variable stored on stack */<br />
char *ptr; /* automatic variable stored on stack */<br />
char *malloc(); /* space allocated stored on heap */<br />
progname = argv[0];<br />
printf("argc = %d\n", argc); /* read-only data */<br />
for (i = 1; i < argc; i++)<br />
{<br />
ptr = malloc(strlen(argv[i]) + 1);<br />
strcpy(ptr, argv[i]);<br />
if (debug)<br />
printf("%s\n", ptr); /* read-only data */<br />
}<br />
} /* functions main, printf, strlen, strcpy &<br />
malloc are all in <strong>the</strong> text segment */<br />
! Process ID (PID)<br />
int getpid();<br />
0-30000<br />
PID 1 special process called <strong>the</strong> init process<br />
PID 0 kernel process called swapper/scheduler<br />
PID 2 kernel process called pagedaemon<br />
! Parent Process ID<br />
int getppid();<br />
! Real User ID<br />
unsigned short getuid();<br />
Each user is assigned an unique ID in /etc/passwd.<br />
! Real Group ID<br />
unsigned short getgid();<br />
Groups of users are assigned an ID in /etc/group.<br />
! Effective User ID<br />
unsigned short geteuid();<br />
Set-user-ID program - file's owner ID is zero<br />
(superuser)<br />
! Effective Group ID<br />
unsigned short getegid();<br />
Set-group-ID program<br />
! Superuser<br />
User ID zero - login name root<br />
Superuser can terminate any o<strong>the</strong>r process on system.<br />
! Password File<br />
/etc/passwd<br />
login-name:password:user-ID:group-ID:misc:home:shell<br />
#include <br />
struct passwd *getpwuid(int uid);<br />
struct passwd *getpwnam(char *name);<br />
struct passwd {<br />
char *pw_name; /* login-name */<br />
char *pw-passwd; /* encypted-password */<br />
int pw_uid; /* user-ID */<br />
int pw_gid; /* group-ID */<br />
char *pw_age; /* password age System V */<br />
char *pw_gecos; /* miscellany */<br />
char *pw_dir; /* home directory */<br />
char *pw_shell; /* shell */<br />
};<br />
111