I’m working on a dummy Unix-like OS (OS161) and I will want to implement processes similar to how Unix does it, meaning fork(), execv(), getpid(), waitpid().
To start, I need to actually have the notion of a process, and give each one its own process ID, some unique integer value to differentiate them. From what I know, each process associates with itself an address space, and at least one thread; possibly more. Let’s keep it to one for now.
So my first thought to create a the notion of a process is to give each thread and address space its associated with a unique process ID, and create a global list variable (a hash table? linked list?) containing all the PIDs. In particular, I currently have available:
struct thread;
struct addr_space;
So I could go into these structures and add a “PID” field as an integer. Alternatively, I was thinking I could just create a wrapper “struct process” and include a thread (or list of threads) and an address space as members.
[Note: currently the thread structure I have has an address space struct as one of its members… Does this mean it’s already essentially a process? I can provide more details, for reference I’m working with OS161]
Finally, there’s the issue of how I should store the PIDs. I’m pretty sure it has to be a global list structure of some sort (similar to the various queues associated with threads) but not sot sure what would be advisable.
Cheers.
In Unix systems theres an odd distinction between process and threads as they are both essentially managed by the same structure (task_struct in Linux).
Threads belonging to the same process share a PID and simply use parent/child pointers to track who spawned who for cleanup and creation. Hash table is probably a good option for storing them. As long as your address space keeps appropriate VM mappings then you should be okay with a similar scheme.