//1:57 PM 12/17/02
Process

A process typically has the arrangement shown in the diagram (pls refer). The user context of a process consists of the portions of the address space that are accesible to the process while its running in user mode.

The text portion of a process contains the actual machine instructions that are executed by the hardware. When a program is executed by the OS, the text portion is read into memory from its disk file, unless the OS supports shared text and copy of the program is already being executed.

The data portion contains the program's data. It is possible for this to be divided into 3 pieces:

The heap is used while a process is running to allocate more data space dynamically to the process.

The stack is used dynamically while the process is running to contain the stack frames that are used by many programming languages. The stack frames contain the return address linkage for each function call and also the data elements required by a function.

A gap is shown between the heap and the stack to indicate that many operating systems leave some room between these two portions, so that both can grow dynamically during the execution of a process.

The kernel context of a process is maintained and accessible only to the kernel. This area contains information that the kernel needs to keep track of the process and to stop and restart the process while other processes are allowed to execute. Typical elements in this area are the machine registers corresponding to the process, the physical locations and sizes of each portion of the process and so on.

contoh program yang menggambarkan "arrangement of a user process" dinyatakan seperti berikut:
----------------------------------------------------------------------------------------------
#include<stdio.h>
int debug=1;
char *progname;

main(argc, argv)

int argc;
char *argv[];
{
  int i;
  char *ptr, *malloc();

  progname=argv[0];
  printf("bilangan argumen(argc) = %d", argc);
  for (i=1; i<argc; i++){
    ptr=malloc(strlen(argv[i])+1);
    strcpy(ptr,argv[i]);
    if (debug)
      printf("\nargumen user telah input: %s",ptr);
   }
}
-------------------------------------------------------------------------------------------------------------------------------
lokasi
//#include<stdio.h>

int debug=1; //stored as initialized read-write data
char *progname; //stored as uninitialized data.

main(argc, argv)

int argc;
char *argv[];
{
  int i;    //i and ptr are called automatic variable. store on the stack
  char *ptr, *malloc();//malloc functin store on the heap

  progname=argv[0];
  printf("bilangan argumen(argc) = %d", argc); //"argc=%d\n" and "%s\n" stored as read-only data
  for (i=1; i<argc; i++){
    ptr=malloc(strlen(argv[i])+1);
    strcpy(ptr,argv[i]);
    if (debug)
      printf("\nargumen user telah input: %s",ptr);
   }
}

//main, printf, strlen, strcpy are all in the text segment.
-------------------------------------------------------------------------------------------------------------

Process ID(PID)
Every process has a unique process ID or PID. The PID is an integer, typically in the range 0 through 30000. The kernel assgins the PID when a new process is created and process can obtain its PID using the getpid system call.

int getpid();

The process with process ID 1 is a special process called the init process.

Parent Process ID
Every process has a parent process, and a corresponding parent process ID.
The kernel assigns the parent process ID when a new process is created and a process can obtain its value using the getppid system call.

int getppid();

Real User ID
Each user is assigned a positive integer user ID. A process can obtain the real user ID of the user executing the process by calling the getuid system call.

unsigned short getuid();
---------------------------------------------------------
review: what is unsigned short????

keyword               range
int                           -2,147,483,648 to 2,147,483,648 (compiler baru)
                               -32768 to 32678 (compiler lama)  (%d)
long int                    -2,147,483,648 to 2,147,483,648  (%d)
unsigned long int       0 to 4,294,967,295
short int                  -32,768 to 32,767
unsigned short int      0 to 65,535  (%u)
unsigned int              0 to 65,535
                               0 to 4,294,967,295
-----------------------------------------------------------
The file /etc/passwd maintains the mapping between login name and numeric user IDs. The numeric user ID is used, for e.g. in the filesystem to record the owner of a file. For most login names on a UNIX/SunOs system, there is a unique user ID assigned to each user.

Real Group ID
Real Group ID. This ID typically used to aggregate the users of a Unix system into project groups or administrative depts. A process can obtain its real group
ID by calling the getid system call.

unsigned short getgid();

Effective User ID
Each process also has an effective user ID. A process can obtain its effective user ID by calling the geteuid system call.

unsigned short geteuid();

Normally this value is the same as the real user ID.

Effective Group ID
Each process also has an effective group ID. A process can obtain its effective group id by calling the gategid system call.

unsigned short getegid();

Normally this value is the same as the real group ID.
The program
(Let me show You....)

------------------------------------------------------------------------

#include<stdio.h>
#include<stdlib.h> /*untuk system*/
#include<unistd.h>/*untuk getgid() geteuid() getpid() getppid()*/
int main()
{
system("clear");
printf("Proses id = %d\n", getpid());
printf("Parent proses id = %d\n",getppid());
printf("Real user id = %u\n",getuid());
printf("Real group id = %u\n", getgid());
printf("Effective user id = %u\n", geteuid());
printf("Effective group id = %u",getegid());
return 0;
}
--------------------------------------------------------------------------