16.05.2015 Views

Working with the Unix OS

Working with the Unix OS

Working with the Unix OS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Processes I<br />

Process States<br />

1. Executing in user mode<br />

2. Executing in kernel mode<br />

3. Not executing but ready to run<br />

4. Sleeping (e.g.: I/O wait)<br />

Processes can't be pre-empted while in kernel mode (o<strong>the</strong>rwise mutual exclusion problems)<br />

Kernel Data Structures<br />

- Most fixed size<br />

- Limiting approach but fast and simple<br />

- If expansion beyond limits is needed <strong>the</strong>n failure occurs<br />

- Simple loops usually used to find spare entries<br />

One Special User<br />

- Super user (root)<br />

- uid = 0<br />

- gid = 0<br />

A process is <strong>the</strong> ordered execution of a set of instructions (a "thread of execution") operating on a specific input.<br />

Most programs when executed constitute a single process. None<strong>the</strong>less, in many applications, it is efficient – ei<strong>the</strong>r<br />

in terms of computer hardware utilization or just to allow re-use of existing software – to build programs<br />

consisting of several processes which are largely independent but which exchange intermediate results from time<br />

to time ("co-operating sequential processes").<br />

In 'C', such programs are built using <strong>the</strong> system calls: fork and usually, though not necessarily: exec<br />

This allows <strong>the</strong> construction of sophisticated control programs which can be used to dispatch and monitor a whole<br />

set of (utility) processes.<br />

Related Systems Calls: wait, exit<br />

! fork system call<br />

produces a clone (child) process:<br />

int fork() /* create a new process */<br />

/* returns process_id and 0 on success or –1 on failure*/<br />

child process has an almost exact copy of<br />

- parent's code<br />

- parent's user data<br />

- parent's system data (e.g. environment)<br />

void forktest()<br />

{<br />

int pid;<br />

printf ("Start of test\n");<br />

pid = fork();<br />

printf ("Returned %d\n",pid);<br />

}<br />

output: start of test<br />

Returned 0<br />

Returned 93<br />

Some of <strong>the</strong> parent's system data is NOT inherited:<br />

- process-id, parent process-id<br />

- execution times reset to zero<br />

Also, while file descriptor table (parent-process open file table) is copied exactly, <strong>the</strong> file pointer open file table) is<br />

shared and if <strong>the</strong> child closes its FD, <strong>the</strong> parent's is undisturbed.<br />

exec system calls<br />

94

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!