Thursday, January 10, 2008

DPS912 Lecture 2: January 10, 2008

Lecture 2: Processes

A program that is loaded into memory and ready to run. One program runs per CPU, all other processes are waiting. UNIX uses timeslices to determine which process gets to run.

Learning about PS (ps afux on matrix)
- PID process identifier
- PPID parent process identifier

In C programming we want to use some process stuff
getpid() - gets the PID of the process
getppid() - gets the PPID of the process
system() - runs a unix command in via string ie system("clear"); DO NOT USE

exec() - starts a new program running within the current program... in fact it replaces it.
- execl - specify the path
- execlp - do not need to specify path if program is on $PATH
- execle - same as execl but pass a new environment variables
- execv - execvp - execve -
- exec never returns except for errors
exec by itself doesn't make much sense, you will always probably use it with fork

fork() - fork allows us to spawn a new child
- new process is identical in almost every way
- inherits the file descriptors, sockets, etc!
- not connected, as separate as any other two processes (although one is child of other)
- watch for concurrency issues because of file desc, sockets

- makes a parent process wait for the child to finish
- needed to prevent zombies and orphans
- waits for all children, and is blocking

- we can make waitpid non-blocking
- waits for a specific child

No comments: