Operating Systems - Processes
Operating Systems - Processes
Processes
ECE 344
• Process state
• Program counter
• CPU registers
• CPU scheduling information (e.g., priority,
scheduling queue information)
• Memory management information (e.g., base
and limit registers)
• Accounting information (e.g., time)
• I/O status information
process ID
registers
struct thread {
struct pcb t_pcb;
char *t_name;
const void *t_sleepaddr;
char *t_stack;
struct addrspace *t_vmspace;
struct vnode *t_cwd;
};
ECE 344 Operating Systems
$ more arch/mips/include/pcb.h
/*
* Process Control Block: machine-dependent part of thread
*/
struct pcb {
// stack saved during context switch
u_int32_t pcb_switchstack;
// stack to load on entry to kernel
u_int32_t pcb_kstack;
// are we in an interrupt handler?
u_int32_t pcb_ininterrupt
// recovery for fatal kernel traps
pcb_faultfunc pcb_badfaultfunc;
// jump area used by copyin/out etc.
jmp_buf pcb_copyjmp; };
ECE 344 Operating Systems
Process Organization in BSD
• Address space
– Child is duplicate of parent process
– Child has a program loaded into it’s address
space
• Unix examples
– Fork system call creates a new process
– Exec system call used after a fork to replace
the process’s address space with a new
program
• Let’s look at that ECE
in 344
action …
Operating Systems
#include <stdion.h>
void main(int argc, char* argv[]){
int pid;
pid = fork()
if (pid < 0){ /* error occurred */
fprintf(stderr, “Fork Failed”);
exit(-1);
}
else if (pid == 0) { /* child process */
execlp (“/bin/ls”, “ls”, NULL);
else { /* parent process */
/* parent will wait for child to complete */
wait(NULL);
printf(“Child completed”);
exit(0);
}
} ECE 344 Operating Systems
integer variable process
pid=fork() parent
time
child’s PID
child parent
pid=0 pid=234562
newly created