0
0
Operating Systemsknowledge~10 mins

Process creation (fork and exec) in Operating Systems - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a new process using fork.

Operating Systems
pid = [1]()
Drag options to blanks, or click blank then click option'
Aspawn
Bexec
Cfork
Dclone
Attempts:
3 left
💡 Hint
Common Mistakes
Using exec instead of fork to create a process.
Confusing spawn or clone with fork.
2fill in blank
medium

Complete the code to replace the current process image with a new program using exec.

Operating Systems
exec[1]("/bin/ls", "ls", "-l", NULL);
Drag options to blanks, or click blank then click option'
Afork
Bexecvp
Cexecv
Dexecl
Attempts:
3 left
💡 Hint
Common Mistakes
Using fork instead of exec to replace the process image.
Confusing execv (which takes an array) with execl (which takes a list).
3fill in blank
hard

Fix the error in the code to correctly create a child process and run a new program.

Operating Systems
pid = fork();
if (pid == 0) {
    [1]("/bin/echo", "echo", "Hello", NULL);
} else {
    wait(NULL);
}
Drag options to blanks, or click blank then click option'
Aexecl
Bexecvp
Cexit
Dfork
Attempts:
3 left
💡 Hint
Common Mistakes
Calling fork again inside the child process.
Using exit instead of exec to run the new program.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps process IDs to their status if the status is 'running'.

Operating Systems
{pid: status for pid, status in processes.items() if status [1] [2]
Drag options to blanks, or click blank then click option'
A==
B"running"
C!=
D"stopped"
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' causing wrong filtering.
Using the wrong status string like 'stopped'.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase process names to their IDs if the ID is greater than 1000.

Operating Systems
{ [1]: [2] for [3], name in process_list if [3] > 1000 }
Drag options to blanks, or click blank then click option'
Aname.upper()
Bname
Cpid
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'id' instead of 'pid' as the loop variable.
Using 'name' instead of 'name.upper()' for the key.