[{"id":"linuxintermediate-001","courseId":"linux-intermediate","domain":"processes-and-scheduling","topic":"SCHED_OTHER fair sharing","prompt":"A team tunes the nice values of SCHED_OTHER threads on a modern Linux kernel. Which TWO statements about nice values are true?","hint":"Consider which unit the nice value is attached to, and how strongly one step changes the share.","explain":"The nice value tilts how the time-sharing scheduler divides CPU among SCHED_OTHER tasks. Small changes in nice can shift shares a lot, so the range and the effect of each step are worth knowing.","source":"https://man7.org/linux/man-pages/man7/sched.7.html","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"Two threads in the same process can have different nice values.","why":"On Linux the nice value is a per-thread attribute, unlike the per-process model POSIX describes."},{"id":"b","text":"Each unit of nice difference makes the scheduler favor the higher-priority process by a factor of 1.25.","why":"The current implementation makes each nice unit a factor of 1.25 in favor, so small steps matter."},{"id":"c","text":"Modern Linux nice values run from 0 to 39.","whyNot":"Modern Linux runs nice from -20 (high priority) to +19 (low priority)."},{"id":"d","text":"Linux keeps one nice value per process, shared by all of its threads.","whyNot":"That is the per-process model; on Linux each thread can carry its own nice value."},{"id":"e","text":"Nice values also tune the priority of SCHED_FIFO threads.","whyNot":"Nice affects only SCHED_OTHER and SCHED_BATCH processes, not SCHED_FIFO threads."},{"id":"f","text":"A nice value of +19 guarantees a process at least a fixed CPU share.","whyNot":"At +19 a process gets little CPU whenever higher-priority load exists."}],"answer":"ab","explanation":"On Linux the nice value is per-thread, and each unit of nice difference scales the scheduler's favor by a factor of 1.25.","concept":"On Linux the nice value is per-thread, and each unit of nice difference scales the scheduler's favor by a factor of 1.25.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Nice tilts CPU share among SCHED_OTHER threads, and on Linux it is set per thread, not per process."]},{"id":"linuxintermediate-002","courseId":"linux-intermediate","domain":"processes-and-scheduling","topic":"Lazy preemption and real-time tasks","prompt":"On Linux 6.13 or later with CONFIG_PREEMPT_RT, selecting CONFIG_PREEMPT_LAZY makes real-time tasks less eager to preempt running work.","hint":"Ask which kind of task the lazy model is said to affect, and whether real-time policies are included.","explain":"Real-time kernels offer several preemption models, and the lazy one is only a tuning choice. Each model's effect is scoped to certain task classes, so check which ones it covers.","source":"https://man7.org/linux/man-pages/man7/sched.7.html","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"The lazy model is less eager only toward SCHED_NORMAL tasks; it does not affect real-time tasks."},{"id":"b","text":"False","why":"The lazy model does not affect real-time tasks, so selecting it leaves their preemption unchanged."}],"answer":"b","explanation":"CONFIG_PREEMPT_LAZY is less eager to preempt SCHED_NORMAL tasks and does not affect real-time tasks.","concept":"CONFIG_PREEMPT_LAZY is less eager to preempt SCHED_NORMAL tasks and does not affect real-time tasks.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Lazy preemption is scoped to SCHED_NORMAL tasks; real-time tasks are not changed by it."]},{"id":"linuxintermediate-003","courseId":"linux-intermediate","domain":"processes-and-scheduling","topic":"CPU affinity masks","prompt":"A process pinned to CPUs 2 and 3 with sched_setaffinity() calls fork(). Which CPU affinity mask does the new child process have?","hint":"Think about what a new process copies from its parent, and what it does not reset.","explain":"A forked child starts as a copy of its parent in many respects. Consider which per-thread scheduling settings the kernel carries over at fork, and which, if any, it resets.","source":"https://man7.org/linux/man-pages/man2/sched_setaffinity.2.html","interaction":{"type":"single"},"options":[{"id":"a","text":"The same mask, CPUs 2 and 3","why":"A child created by fork(2) inherits its parent's CPU affinity mask unchanged."},{"id":"b","text":"All CPUs, since the child starts unpinned","whyNot":"The mask is not reset on fork; the child keeps the parent's restriction."},{"id":"c","text":"CPU 0 only, the default for new processes","whyNot":"A forked child copies the parent's mask; nothing resets it to CPU 0."},{"id":"d","text":"Only the CPU that was running fork()","whyNot":"The child copies the whole mask, not just the single CPU the parent happened to run on."}],"answer":"a","explanation":"A child created by fork(2) inherits its parent's CPU affinity mask, and execve(2) keeps that mask too.","concept":"A child created by fork(2) inherits its parent's CPU affinity mask, and execve(2) keeps that mask too.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Affinity survives fork and exec, so a child keeps the parent's CPU pinning unless it changes it."]},{"id":"linuxintermediate-004","courseId":"linux-intermediate","domain":"processes-and-scheduling","topic":"Async-signal-safe calls","prompt":"A program's SIGINT handler needs to call one library function. The main code may be in the middle of printf() when the signal arrives. Which call is safe in the handler?","hint":"Think about which functions are guaranteed reentrant or atomic with respect to signals.","explain":"A signal handler can interrupt any code, including a library call halfway through updating its state. Only functions that are reentrant or atomic with respect to signals can be called from one.","source":"https://man7.org/linux/man-pages/man7/signal-safety.7.html","interaction":{"type":"single"},"options":[{"id":"a","text":"getpid(2), which returns the process ID","why":"getpid(2) is on POSIX's list of async-signal-safe functions, so a handler may call it."},{"id":"b","text":"printf(3), which formats output to stdout","whyNot":"stdio functions are not async-signal-safe; an interrupted printf may leave its buffer half-updated."},{"id":"c","text":"malloc(3), which allocates heap memory","whyNot":"malloc is not on the POSIX list of async-signal-safe functions, so a handler cannot assume it is safe."},{"id":"d","text":"fprintf(3), which writes formatted text to a stream","whyNot":"All stdio functions are unsafe in a handler because they keep shared buffer state."}],"answer":"a","explanation":"Only functions on POSIX's async-signal-safe list may be called from a handler; stdio functions are not on it, while getpid(2) is.","concept":"Only functions on POSIX's async-signal-safe list may be called from a handler; stdio functions are not on it, while getpid(2) is.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Inside a signal handler, call only async-signal-safe functions; stdio and malloc are not on that list."]},{"id":"linuxintermediate-005","courseId":"linux-intermediate","domain":"processes-and-scheduling","topic":"SA_RESTART restarts calls","prompt":"A handler is installed with SA_RESTART. Which TWO of these blocking calls still fail with EINTR when a signal interrupts them?","hint":"Some interfaces are restarted by SA_RESTART, but a few categories are never restarted.","explain":"SA_RESTART asks the kernel to restart some interrupted system calls rather than fail them with EINTR. Which calls qualify depends on their category, so the exceptions matter as much as the rule.","source":"https://man7.org/linux/man-pages/man7/signal.7.html","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"epoll_wait(2)","why":"epoll_wait is never restarted after a handler interrupts it, even with SA_RESTART."},{"id":"b","text":"nanosleep(2)","why":"Sleep interfaces such as nanosleep always fail with EINTR when a handler interrupts them."},{"id":"c","text":"read(2) from a pipe","whyNot":"Reads from a pipe are slow-device I/O, and SA_RESTART restarts them."},{"id":"d","text":"wait4(2) for a child","whyNot":"The wait family (wait, waitpid, waitid, wait4) is restarted under SA_RESTART."},{"id":"e","text":"flock(2) on a file","whyNot":"File locking with flock(2) is among the interfaces that SA_RESTART restarts."},{"id":"f","text":"connect(2) with no socket timeout","whyNot":"Socket connect is restarted unless a timeout has been set on the socket."}],"answer":"ab","explanation":"SA_RESTART restarts slow-device I/O, wait and file-lock calls, but sleep, poll/select/epoll and System V IPC calls always fail with EINTR.","concept":"SA_RESTART restarts slow-device I/O, wait and file-lock calls, but sleep, poll/select/epoll and System V IPC calls always fail with EINTR.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["SA_RESTART does not cover sleep, epoll, poll or select calls; code must still handle EINTR there."]}]