15-213 Lecture Q&A Through Test #2


Sunday, March 17, 2002

Question:

execl("/user/bin/cp", "cp", "foo", "bar", 0);

In the above function, what does "cp", "foo", and "bar" arguments mean?

Answer:

They are the command line arguments. The last 0 is needed so that execl knows when to stop.


Friday, March 15, 2002

Question:

Where is the PID of each process stored... in a hidden variable?

Answer:

The PID of each process is stored within the operating system in a per-process data structure that keeps the information about the process. In modern operating systems this data structure is usually called a "task_struct". Traditionally, it was known as the "process control block" or PCB. Basically, it holds or names all of the OS state associated with the process. The operating system keeps track of the process by enqueing this structure on various queues or lists, each one represents a different state.


Thursday, March 14, 2002

Question:

pid_t waitpid(pid_t pid, int *status, int options);

1. when setting pid = -1, and options = "WUNTRACED", it suspends execution of the calling process until all parent's children processes are terminated or just until any one of child process is terminated?

2. if it suspends execution of calling function until all parent's children processes, what could be the return value?

Answer:

This will wait for any children. WUNTRACED just makes it so that waitpid returns for any stopped children whose status has not yet been reported.