Saturday, May 20, 2017

Network Programming - Second Semester 2016-17 : Mid-Semester Test (EC- 2 Regular)

Birla Institute of Technology & Science, Pilani
Work-Integrated Learning Programmes Division
Second Semester 2016-2017

Mid-Semester Test
(EC-2 Regular-SOLUTION)

Course No.  : IS ZC462
Course Title  : NETWORK PROGRAMMING
Nature of Exam  : Close Book 
Weightage  : 30% 
Duration                : 2 Hours  
Date of Exam  : 26/02/2017 (AN) 



Q.1.       What are various IDs associated with a process?                                          [4]

·        Unix identifies each process with a unique integer called ProcessID.
·    The process that executes the request for creation of a process is called the 'parent process' whose PID is 'Parent Process ID'.
·    Every process is associated with a particular user called the 'owner' who has privileges over the process. The identification for the user is 'UserID'. Owner is the user who executes the process.
·      Process also has 'Effective User ID' which determines the access privileges for accessing resources like files.

§  getpid() -process id
§  getppid() -parent process id
§  getuid() -user id
§  geteuid() -effective user id

                                                                                                      
Q.2.       What is Zombie process in UNIX? How do you find Zombie process in UNIX?   [4]

o   Kernel keeps information (process ID, the termination status of the  process, and the amount of CPU time taken by the process ) until  parent asks for it.
o   a process that has terminated, but whose parent has not yet waited  for it, is called a zombie.
o   Zombies can hold up pids and resources in long-live servers.
If we use the following command we can see which process are zombies.
ps -el | grep 'Z'

With a normal ps -el command you see an output with in the second colum the state of the process. Here are some states:
S: sleeping
R: running
D: waiting (over het algemeen voor IO)
T: gestopt (suspended) of getrasseerd
Z: zombie (defunct)



                                                                                                      
Q.3.       What are the process states in Unix?                                                              [6]


Running: Process is either running or ready to run

Interruptible: A Blocked state of a process and waiting for an event or signal from another process

Uninterruptible: a blocked state. Process waits for a hardware condition and cannot handle any signal

Stopped: Process is stopped or halted and can be restarted by some other process

Zombie: process terminated, but information is still there in the process table.


Q.4.       What is Inode? Explain the content of Inode.                                                   [6]

A file system’s i-node table contains one i-node (short for index node) for each file residing in the file system. I-nodes are identified numerically by their sequential location in the i-node table. The i-node number (or simply i-number) of a file is the first field displayed by the ls –li command. 

The information maintained in an i-node includes the following:


􀁺 File type (e.g., regular file, directory, symbolic link, character device).
􀁺 Owner (also referred to as the user ID or UID) for the file.
􀁺 Group (also referred to as the group ID or GID) for the file.
􀁺 Access permissions for three categories of user: owner (sometimes referred to as user), group, and other (the rest of the world). 
􀁺 Three timestamps: time of last access to the file (shown by ls –lu), time of last modification of the file (the default time shown by ls –l), and time of last status change (last change to i-node information, shown by ls –lc). As on other UNIX implementations, it is notable that most Linux file systems don’t record the creation time of a file.
􀁺 Number of hard links to the file.
􀁺 Size of the file in bytes.
􀁺 Number of blocks actually allocated to the file, measured in units of 512-byte blocks. There may not be a simple correspondence between this number and the size of the file in bytes, since a file can contain holes (Section 4.7), and thus require fewer allocated blocks than would be expected according to its nominal size in bytes.
􀁺 Pointers to the data blocks of the file.




Q.5.       What is the purpose of alarm and pause functions?                                        [4]


Alarm Function :

      #include <unistd.h>
      unsigned int alam( unsigned int seconds );
      /* Always success, returning number of seconds remaining on any previously set timer, or 0 if no timer previously was set */

        alarm() call is used to set a real-time timer in seconds. After expiry, it generates SIGALRM signal.
        alarm(0) cancels the existing timer.
        In Linux, there can be only one timer per process. Among setitimer() and alarm(), only one timer can be running at a give time.

Pause Function :

        The pause() function suspends the calling thread until the delivery of a signal whose action is either to execute a user-defined signal handler or to terminate the process

#include <unistd.h>
int pause(void);

        If the action is to terminate, pause() does not return
        If a signal is caught by the process, pause() returns after the signal handler returns
        The pause() function always returns 1
        If interrupted by a signal, pause() sets errno to EINTR
        To wait for a particular signal by using pause(), a program must determine which signal caused pause() to return
        This information is not directly available, so the signal handler must set a global flag for the program to check after pause() returns




Q.6.       Explain the memory segments of process in UNIX?                                             [6]


A process is logically divided into the following parts, known as segments:

1. Text or Code Segment
2. Initialized Data Segments
3. Uninitialized Data Segments
4. Stack Segment
5. Heap Segment
  

The text segment contains the machine-language instructions of the program run by the process. The text segment is made read-only so that a process doesn’t accidentally modify its own instructions via a bad pointer value. Since many processes may be running the same program, the text segment is made shareable so that a single copy of the program code can be mapped into the virtual address space of all of the processes.

The initialized data segment contains global and static variables that are explicitly initialized. The values of these variables are read from the executable file when the program is loaded into memory.

The uninitialized data segment contains global and static variables that are not explicitly initialized. Before starting the program, the system initializes all memory in this segment to 0. For historical reasons, this is often called the bss segment, a name derived from an old assembler mnemonic for “block started by symbol.” The main reason for placing global and static variables that are initialized into a separate segment from those that are uninitialized is that, when a program is stored on disk, it is not necessary to allocate space for the uninitialized data. Instead, the executable merely needs to record the location and size required for the uninitialized data segment, and this space is allocated by the program loader at run time.

The stack is a dynamically growing and shrinking segment containing stack frames. One stack frame is allocated for each currently called function. A frame stores the function’s local variables (so-called automatic variables), arguments, and return value.

The heap is an area from which memory (for variables) can be dynamically allocated at run time. The top end of the heap is called the program break.



No comments:

Post a Comment