---
# System prepended metadata

title: FAQs on Processes and Scheduling

---

# FAQs on Processes and Scheduling

## `argc` and `argv`

`argc` is the number of arguments given and `argv` stores these arguments. For example, if you have a program that calculates the factorial of a number. You compiled your code and named it as `fact`. When you run `fact 5` in the command line, the `argc` will be `2` and the `argv` will be `{"fact", "5}`. Note that `5` is taken as an array of characters (string) so that you need `atoi` or other functions to convert it back to an integer.

## `fork`

When calling `fork()`, it will make a child process replicate itself, and the child process will start where the `fork()` is called and the value is returned. Look at the following example

```c=
...
if (fork() == 0) {
    // do something
}
...
```

After calling `fork()`, both the parent and the child will execute the equation check `fork() == 0`. Note that the `fork()` has already been called so that it is the comparasion between the return value of `fork()` and `0`. For parent, the return value is the pid of the child and for child it is zero.

## `exec`

`exec` replaces the program with what it calls.

https://stackoverflow.com/questions/4204915/please-explain-the-exec-function-and-its-family/37558902

The following diagram illustrates the typical fork/exec operation where the bash shell is used to list a directory with the ls command:

```shell=
+--------+
| pid=7  |
| ppid=4 |
| bash   |
+--------+
    |
    | calls fork
    V
+--------+             +--------+
| pid=7  |    forks    | pid=22 |
| ppid=4 | ----------> | ppid=7 |
| bash   |             | bash   |
+--------+             +--------+
    |                      |
    | waits for pid 22     | calls exec to run ls
    |                      V
    |                  +--------+
    |                  | pid=22 |
    |                  | ppid=7 |
    |                  | ls     |
    V                  +--------+
+--------+                 |
| pid=7  |                 | exits
| ppid=4 | <---------------+
| bash   |
+--------+
    |
    | continues
    V
```

## Scheduling PP last question

|Task|Duration|frequency|
|-|-|-|
T1 | 15 | 150
T2 | 200 | 300
T3 | 300 |

Every 300 ms, two T1 comsumes 30ms, one T2 consumes 200ms, therefore T3 has 70ms to go and can be done eventually.

If T1 comsumes 50. Every 300 ms there will be no time left for T3.