Task 1: - Weebly



Task 1:How to run a program in Linux. Task 2:Write a program that adds two numbers.Task 3:Write a command for terminal that show all the commands used by the user. Task 4:Write a note on following system calls (2-3 lines) Fork()Fork creates the child process which is in fact the copy of the current process. But the PID and PPID is different of both child and parent process. On success, the PID of the child process is returned in the parent’s thread of execution, and a 0 is returned in the child’s thread of execution. On failure, a -1 will be returned in the parent’s context, no child process will be created.Exec()The exec () system call loads a binary file into memory (destroying the memory image of the program containing the exec () system call) and starts its execution.Exec is a functionality of an operating system that runs an executable file in context of an already existing process, replacing the previous executable.Getpid()When Getpid() is used, it returns process ID of the calling process.Getppid()Getppid() is used to get the process ID of the parent process.Getgrpid()The Getgrpid() function returns a pointer to a structure containing the broken-out fields of the record in the group database that matches the group ID. Wait()The wait() system call suspends the execution of the current process until one of its children terminates. In the case of a terminated child, performing a wait allows the system to release the resources associated with the child; if a wait is not performed, then terminated the child remains in a "zombie" stateSleep()A computer program may sleep, which places it into the inactive state for a period of time. Eventually the expiration of an interval timer or the receipt of a signal or interrupt causes the program to resume execution.The sleep () function is called providing a single parameter of type unsigned integer of the number of seconds to sleep.Exit()Exit () system call is called by a process which wants to voluntarily terminate itself. It returns the invoking process a status code of 0 for successful termination and non zero error code.Task 5:Why we use vfork (). Write difference between fork () and vfork(). Fork : The fork call basically makes a duplicate of the current process, identical in almost every way the child process gets a different PID and has the the PID of the old process (parent) as its PPID. The child gets 0 and the parent gets the PID of the child. If no child is created and the parent gets an error code.Vfork : The basic difference between vfork and fork is that when a new process is created with vfork(), the parent process is temporarily suspended, and the child process might borrow the parent's address space. This strange state of affairs continues until the child process either exits, or calls execve(), at which point the parent process continues.Task 6: List system calls belong to exec family. (2-3 lines for each system call). ExeclExecleExeclpExecvExecveexecvpTask 7: Write a program to create a simple child process and display processes id, parent ids, user ids and group ids to which it belongs. Task 8: Write a program that display “child created” and if the child not creates it display “Child not created”. Task 9:Which system call is use to get the user id where the process is executing. Task 10: Which command is use to display the processes tree Task 11: Write a code that contains a. Global variable for result and assign some value b. Create a child c. Child process find the square of result d. Parent process find the cube of result e. Both processes store the answer In result variable Task 12: Is it possible that the child process is live and the parent terminates? (Explain with example). If it is the case then what will be the parent of that child? (display the id of parent and child process) Yes it is possible that the child process is living while its parent process terminates. In this case, child process becomes an orphan process and its parent process will be the init process.a ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download