A process is a sequence of operations performed by a program running. A program becomes process at the time it enters running, even if a program can be divided into multiple independent processes. A sequential process is a deterministic process, in the sense that given the same input will always produce the same output. A process is defined by the contents of machine registers, the stack of the process from data section and from the heap.
A process can be found in various states of execution.
Only one process can be found in the state of Running in a given time. The PCB photographing process, storing the state of the process, the PC, the status registers, the priority, the list of memory locations in use, the information on disk I / O and other information from the OS dependent. With the use of PCBs can handle multiple concurrent processes, and thus give the impression that the CPU performs multiple tasks simultaneously, when it assigns to each process running on a given execution time. On UNIX systems, the PCB is implemented in C using the structure task struct.
There are two types of scheduler processes. Those long-term process selects which add to the list of ready tasks, the short-term decides which process should execute. Processes can be classified into two categories: I / O bound, if you take a long execution time for the I / O or CPU bound, if they require many calculations.
A parent process can create child processes that in turn can create child processes. This leads to the creation of a process tree. All processes are identified by a process identifier (PID), unique, normally full. Depending on the OS pososno father and child share the address space or not, even partially. Very often, the father's address space is duplicated by the kernel, but the child has the opportunity to change it and then make it equal to that of the father.
During the execution you can have two behaviors: either the father expects his children die, or to contribute.
Termination of processes
A process ends with the system call void exit (int status) that closes all file descriptors, free address space, save the first byte of the status of the process table, it sends a SIGCHLD signal to the father. If a father dies the children become INIT with PID = 1.
Suspension of processes
unsigned int sleep (unsigned int n) suspends the process for n seconds. returns 0 if the suspension has been successful or returns the time that he had to sleep
Independent processes / cooperating
A process is independent if it can not be conditioned by the execution of other processes, nor can influence the behavior of others. A cooperative process, however, can vary in its execution depending on the behavior of others.
The benefits of cooperation are the ability to share information, increase the speed of calculation (because the subtasks are performed in parallel), and modularity. The cooperation may be made through the use of a shared memory. Another method is to exchange messages, useful for small amounts of data and does not require the use of system calls.
A thread is constituted by the program counter, by a set of registers and a stack. A thread shares with other threadscompeting section of code, data section and OS resources, such as open files and signals. In a process composed of multiple threads in case a thread is waiting can be carried out another thread of the same process. The processes are independent while the thread may have common resources.
There are basically two types of threads. The user-level threads are supported by user-level system calls. The advantages arespeed between threads of the same process and can be implemented on any kernel. The disadvantages are at the moment when a thread performs a blocking because all threadsare blocked in the same process and in addition are executed sequentially in a multiprocessor system. The kernel is generated by calling thread inveve system calls. They are managed by the OS and then pososno be scheduled and executed in parallel on a multiprocessor system. The context switch is however moreexpensive and it is necessary to establish a maximum of threadsper process.
One method is through the functions of start, which means thatthe process is dirami into two streams. The moment you callComplete the two streams come together and take up the samethread of execution. Another method is where you begin calling other processes running other pieces of code. The constructcobegin allows parallel execution of multiple processes. COEND instructions waiting for their order. With these constructs can not develop any type of graph. The rules for competition are expressed by the conditions of Bernstein who say that the writerscan not write when someone writes or reads. This is the principleupon which mutual exclusion.