Difficulty: Easy
Correct Answer: stty intr \^c
Explanation:
Introduction / Context:
The terminal driver maps certain key combinations to control signals such as interrupt (INTR), quit, and erase. Customizing these mappings with 'stty' is useful on atypical keyboards or when your environment defaults differ. Here, we want Control-C to serve as the interrupt key that sends SIGINT to foreground processes.
Given Data / Assumptions:
Concept / Approach:
Use 'stty intr ^c' to set the INTR character. In many shells, the caret sequence is interpreted by 'stty' itself, but to avoid shell expansion issues, it is common to escape the caret as '\^c'. This ensures the literal control notation is passed correctly. After this change, pressing Control-C sends SIGINT to the foreground job as expected.
Step-by-Step Solution:
Verification / Alternative check:
Run 'stty -a' again to see 'intr = ^C' reported. Start 'sleep 100' and press Ctrl-C; it should terminate with SIGINT.
Why Other Options Are Wrong:
Common Pitfalls:
Forgetting to escape special characters in some shells, or confusing 'erase' with 'intr'. Also note that some environments already default to ^C for interrupt.
Final Answer:
stty intr \^c
Discussion & Comments