LFCS Process and Job Scheduling Questions and Answers — Questions and Answers
Question 1: A system administrator needs to schedule a backup script located at `/usr/local/bin/backup.sh` to run every day at 3:30 AM. Which of the following is the correct crontab entry to accomplish this?
- `* * 3 30 * /usr/local/bin/backup.sh`
- `at 3:30am /usr/local/bin/backup.sh`
- `30 3 * * * /usr/local/bin/backup.sh` (Correct answer)
- `30 3 * * * root /usr/local/bin/backup.sh`
Correct answer: `30 3 * * * /usr/local/bin/backup.sh`
The crontab format consists of five time-and-date fields (minute, hour, day of month, month, day of week) followed by the command. The entry `30 3 * * *` correctly specifies 'at minute 30 past hour 3 on every day-of-month, every month, and every day-of-week', which translates to 3:30 AM daily.
Question 2: You need to run a resource-intensive data processing script, `/opt/scripts/process_data.sh`, tonight at 11:00 PM. The task should only be executed once. Which command is the most appropriate for scheduling this job?
- `echo "/opt/scripts/process_data.sh" | at 23:00` (Correct answer)
- `schedule --time 23:00 /opt/scripts/process_data.sh`
- `0 23 * * * /opt/scripts/process_data.sh`
- `cron -e "0 23 1 * * /opt/scripts/process_data.sh"`
Correct answer: `echo "/opt/scripts/process_data.sh" | at 23:00`
The `at` command is designed specifically for scheduling commands to be run once at a particular time in the future. Piping the command string to `at` with a specified time (like 23:00) is the standard method for creating a one-time job.
Question 3: A long-running data compilation process with PID 4567 is consuming excessive CPU, negatively impacting other critical services. Which of the following commands would lower its scheduling priority, making it 'nicer' to other processes?
- `nice -n -10 4567`
- `renice 10 4567` (Correct answer)
- `renice -10 4567`
- `kill -15 4567`
Correct answer: `renice 10 4567`
The `renice` command is used to alter the scheduling priority of a process that is already running. A positive value increases the 'niceness' number (from -20 to +19), which lowers the process's priority and gives it less CPU time. A value of 10 makes the process significantly 'nicer' to other tasks.
Question 4: A system administrator wants to terminate all processes owned by the user `jdoe`. The command should first attempt a graceful shutdown before resorting to more forceful methods. Which command is the most appropriate first step?
- `killall -KILL -u jdoe`
- `kill -9 $(ps -u jdoe -o pid=)`
- `pkill -HUP -u jdoe`
- `pkill -u jdoe` (Correct answer)
Correct answer: `pkill -u jdoe`
The `pkill` command can signal processes based on attributes like the owner's username (`-u jdoe`). By default, `pkill` sends the SIGTERM (15) signal, which requests that processes terminate gracefully, allowing them to save state and exit cleanly. This is the standard and safest first approach to stopping a user's processes.
Question 5: While monitoring system performance with the `top` command, you notice a process that needs its priority adjusted. What is the correct interactive keystroke to use within `top` to 'renice' a process?
- `k`
- `p`
- `r` (Correct answer)
- `n`
Correct answer: `r`
Within the `top` utility's interactive mode, pressing the 'r' key will prompt you to enter the PID of the process you wish to renice, and then the new niceness value to apply. This allows for real-time priority adjustment without leaving the monitoring tool.
Question 6: Which of the following `ps` commands is specifically formatted to display only the process ID (PID), the command name (COMM), and the niceness value (NI) for all processes on the system?
- `ps -ef`
- `ps aux`
- `ps -l`
- `ps axo pid,comm,ni` (Correct answer)
Correct answer: `ps axo pid,comm,ni`
The `ps` command with the `axo` flags allows for custom output formatting. `a` shows processes for all users, `x` shows processes without a controlling tty, and `-o` specifies the columns to display. `pid,comm,ni` explicitly tells `ps` to print the Process ID, Command Name, and Niceness value, providing a clean and targeted output.
A system administrator needs to schedule a backup script located at `/usr/local/bin/backup.sh` to run every day at 3:30 AM.
Which of the following is the correct crontab entry to accomplish this?