1)Difference between fork() and vfork() ?

fork()

vfork()

System Call to create a child process

System call to create a child process and block the parent process

pid_t fork(void) 

pid_t vfork(void);

Both the child and the parent process will have different address space

Both the child and the parent process share the same address space

Any modification done by the child in its address space is not visible to the parent

Process as both will have separate copies

Any modification by child process is visible to both parent and child as both will have the same copies

This uses copy-on -write

This doesn’t use copy-on-write

Both parent and child executes simultaneously

Parent process will be suspended until the child execution is completed

Behaviour is Predictable

Behaviour is Unpredictable


2) Explain nice and renice in Linux?

nice:

 

a)    nice command in linux helps in run a program with modified scheduling priority.

 

Syntax : nice [option] [Command [Arg]..]

 

b)    Niceness values range from -20 to 19.

 

c)    If we give a process higher priority, then kernel allocates more cpu time to that process.

 

renice:


a)    renice command allows you to change and modify the scheduling priority of an already running process.

 

Syntax:  renice [-n] priority [-g|-p|-u] identifier ….


 

b)      Kernel schedules the process and allocates CPU time

Accordingly for each of them.

 3)Explain dup() and dup2() system calls?

dup:

 

a)    The dup () system call creates a duplicate of a file descriptor.

 

Syntax : int dup(int oldfd);

 

b)    It uses the lowest-numbered unused descriptor for the new descriptor.

 

c)    They both refer to the same open file description and copy file descriptors may be used interchangeably.

 

d)    They both refer to the same open file description and thus share file offset and file status flags.

 

dup2:


a)    The dup2 () system call is similar to dup () but the difference between them is that instead of using lowest-numbered unused file descriptor, it uses the descriptor number

specified by the user.

 

Syntax:  int dup2(int oldfd, int newfd);


 

b)    If the descriptor newfd was previously open, it is silently closed before being reused.

 

c)    If oldfd is not a valid file descriptor, then the class fails,

      and newfd is not closed.

    d)if oldfd is a valid file descriptor, and newfd has the same value  

     as oldfd, then dup2() does nothing and returns newfd.