ProcessTutor - UNIX II Systems Programming Session 2...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
UNIX Systems Programming II Short Course Notes Alan Dix ' 1996 II/20 UNIX Systems Programming II Session 2 process handling ¥ UNIX processes and forking ¥ fork system call ¥ exec system call ¥ death of process ¥ kill ¥ fork and I/O using it
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
UNIX Systems Programming II Short Course Notes Alan Dix ' 1996 II/21 A UNIX process UNIX process: ¥ identified by process id (pid) ¥ process includes: program code application data system data including file descriptors code data system data e.g. file descriptors pid = 597
Background image of page 2
UNIX Systems Programming II Short Course Notes Alan Dix ' 1996 II/22 Forking UNIX ’fork’ duplicates process: ¥ copies complete process state: program data + system data including file descriptors ¥ code immutable shared $ echo $$ 597 $ (echo $$) 632 $ code data system data 597 code data system data 632
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
UNIX Systems Programming II Short Course Notes Alan Dix ' 1996 II/23 Forking – 2 ¥ old process called the parent ¥ new process called the child ¥ process ids allocated sequentially so effectively unique (but do wrap after a very long time) ¥ finding process ids at the shell prompt: use ps in a C program: use int p = getpid(); in a shell script: use $$ N.B. useful for naming temporary files: tmpfile = "/tmp/myfile$$"
Background image of page 4
Systems Programming II Short Course Notes Alan Dix ' 1996 II/24 Fork system call pid_t p = fork(); ( pid_t int ) ¥ if successful process successful fork returns: 0 to child process child pid — to parent process parent and child are different! ¥ negative result on failure
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 15

ProcessTutor - UNIX II Systems Programming Session 2...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online