Bird
Raised Fist0
FreeRTOSprogramming~20 mins

vTaskList() for task status dump in FreeRTOS - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
FreeRTOS Task Status Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of vTaskList() buffer content?

Given a FreeRTOS system with three tasks named TaskA, TaskB, and TaskC, each with different states, what will the vTaskList() output buffer contain?

Assume the following states: TaskA is Running, TaskB is Ready, and TaskC is Blocked.

FreeRTOS
char buffer[512];
vTaskList(buffer);
printf("%s", buffer);
A
TaskA       R       1       100     0
TaskB       B       2       80      0
TaskC       R       3       60      0
B
TaskA       Running 1       100     0
TaskB       Ready   2       80      0
TaskC       Blocked 3       60      0
C
TaskA       R       1       100     0
TaskB       R       2       80      0
TaskC       R       3       60      0
D
TaskA       X       1       100     0
TaskB       R       2       80      0
TaskC       B       3       60      0
Attempts:
2 left
💡 Hint

Remember that vTaskList() uses single-letter codes for task states: X=Running, R=Ready, B=Blocked, S=Suspended, D=Deleted.

🧠 Conceptual
intermediate
1:30remaining
What does the 'Stack High Water Mark' value represent in vTaskList() output?

In the output of vTaskList(), there is a column showing the 'Stack High Water Mark' for each task. What does this value represent?

AThe minimum amount of free stack space remaining since the task started.
BThe maximum amount of stack space the task has used since it started.
CThe current amount of free stack space available to the task.
DThe total stack size allocated to the task.
Attempts:
2 left
💡 Hint

Think about what 'high water mark' usually means in memory usage.

🔧 Debug
advanced
2:00remaining
Why does vTaskList() output show incorrect task states?

A developer calls vTaskList() but notices that all tasks show the state 'R' (Ready) even though some tasks are blocked or suspended. What is the most likely cause?

AThe developer called <code>vTaskList()</code> from an interrupt context instead of a task context.
BThe buffer passed to <code>vTaskList()</code> is too small to hold the output.
CThe tasks were created with the same priority, causing state confusion.
DThe developer did not call <code>vTaskStartScheduler()</code> before calling <code>vTaskList()</code>.
Attempts:
2 left
💡 Hint

Consider where vTaskList() is safe to call from.

📝 Syntax
advanced
1:30remaining
Which code snippet correctly calls vTaskList() to print task status?

Choose the correct code snippet that declares a buffer and calls vTaskList() to print the task list to standard output.

A
char buffer[512];
vTaskList(&amp;buffer);
printf("%s\n", buffer);
B
char *buffer;
vTaskList(buffer);
printf("%s\n", buffer);
C
char buffer[512];
vTaskList(buffer);
printf("%s\n", buffer);
D
char buffer[512];
vTaskList(buffer, 512);
printf("%s\n", buffer);
Attempts:
2 left
💡 Hint

Check the function signature of vTaskList() and how buffers are passed in C.

🚀 Application
expert
2:30remaining
How to use vTaskList() output to detect stack overflow in a running system?

You want to monitor your FreeRTOS system for stack overflows by periodically checking the vTaskList() output. Which approach is best to detect a stack overflow early?

ACheck if any task's state is 'B' (Blocked), which means the task is stuck and may have overflowed stack.
BCheck if any task's 'Stack High Water Mark' value is zero or very low, indicating the stack is almost full.
CCheck if the number of tasks reported by <code>vTaskList()</code> is less than expected, indicating a crash.
DCheck if the task priorities have changed unexpectedly in the output.
Attempts:
2 left
💡 Hint

Think about what the stack high water mark tells you about stack usage.

Practice

(1/5)
1. What is the primary purpose of the vTaskList() function in FreeRTOS?
easy
A. To suspend all tasks temporarily
B. To display a list of all running tasks and their current status
C. To delete a task from the scheduler
D. To create a new task with specific priority

Solution

  1. Step 1: Understand the function's role

    vTaskList() is designed to provide a snapshot of all tasks currently managed by FreeRTOS.
  2. Step 2: Identify what it outputs

    The function outputs a formatted string showing each task's name, state, priority, stack usage, and task number.
  3. Final Answer:

    To display a list of all running tasks and their current status -> Option B
  4. Quick Check:

    vTaskList() = task status display [OK]
Hint: Remember: vTaskList() shows task info, not task control [OK]
Common Mistakes:
  • Confusing vTaskList() with task creation functions
  • Thinking it suspends or deletes tasks
  • Assuming it returns a value instead of writing to a buffer
2. Which of the following is the correct way to call vTaskList() to get the task status dump into a buffer named buffer of size 512 bytes?
easy
A. vTaskList(&buffer, 512);
B. vTaskList(buffer, 512);
C. vTaskList(buffer);
D. vTaskList(buffer, sizeof(buffer));

Solution

  1. Step 1: Check vTaskList() function signature

    In FreeRTOS, vTaskList() takes a single argument: a char pointer to a buffer where it writes the task list string.
  2. Step 2: Understand buffer size handling

    The function does not take a size parameter, so passing size is incorrect. The buffer must be large enough, but size is not passed.
  3. Final Answer:

    vTaskList(buffer); -> Option C
  4. Quick Check:

    vTaskList() takes only buffer pointer [OK]
Hint: vTaskList() needs only buffer pointer, no size argument [OK]
Common Mistakes:
  • Passing buffer size as argument (not required)
  • Passing address of buffer pointer (&buffer)
  • Using incorrect function signature
3. Given the following code snippet, what will be the output stored in buffer after calling vTaskList(buffer); if there are two tasks named "TaskA" and "TaskB" running?
char buffer[512];
vTaskList(buffer);
printf("%s", buffer);
medium
A. A formatted table listing TaskA and TaskB with their states, priorities, and stack usage
B. Only the names of TaskA and TaskB separated by commas
C. An empty string because buffer is not initialized
D. A runtime error due to buffer overflow

Solution

  1. Step 1: Understand what vTaskList() writes

    The function writes a formatted string showing all tasks with details like name, state, priority, stack usage, and task number.
  2. Step 2: Analyze the buffer content after call

    Since buffer is large enough (512 bytes), it will contain a readable table listing TaskA and TaskB with their statuses.
  3. Final Answer:

    A formatted table listing TaskA and TaskB with their states, priorities, and stack usage -> Option A
  4. Quick Check:

    vTaskList() output = formatted task table [OK]
Hint: vTaskList() outputs full task info table, not just names [OK]
Common Mistakes:
  • Expecting only task names without details
  • Assuming buffer needs initialization before call
  • Thinking it causes runtime error if buffer is large enough
4. You wrote the following code to get the task list but the output is garbage or empty. What is the most likely cause?
char *buffer;
vTaskList(buffer);
printf("%s", buffer);
medium
A. Buffer pointer is uninitialized and does not point to valid memory
B. vTaskList() requires two arguments, so this call is invalid
C. The buffer size is too large causing overflow
D. vTaskList() only works if tasks are suspended

Solution

  1. Step 1: Check buffer initialization

    The buffer pointer is declared but not assigned memory, so it points to an unknown location.
  2. Step 2: Understand vTaskList() usage

    vTaskList() writes to the buffer pointer, so it must point to valid writable memory (like an array).
  3. Final Answer:

    Buffer pointer is uninitialized and does not point to valid memory -> Option A
  4. Quick Check:

    Uninitialized buffer pointer causes invalid output [OK]
Hint: Always allocate buffer memory before passing to vTaskList() [OK]
Common Mistakes:
  • Passing uninitialized pointer instead of array
  • Assuming vTaskList() needs two arguments
  • Thinking tasks must be suspended for vTaskList() to work
5. You want to monitor task health by periodically dumping task status using vTaskList(). Which approach correctly ensures safe and consistent output without corrupting the buffer?
hard
A. Call vTaskList() from multiple tasks simultaneously using the same buffer
B. Declare a local buffer inside the task and call vTaskList() without synchronization
C. Use vTaskList() with a dynamically allocated buffer freed immediately after call
D. Declare a static buffer globally and call vTaskList() inside a mutex-protected function

Solution

  1. Step 1: Understand buffer sharing risks

    Using a global static buffer avoids repeated allocation and ensures buffer lifetime.
  2. Step 2: Protect buffer access

    Using a mutex prevents concurrent calls corrupting the buffer content.
  3. Step 3: Evaluate other options

    Local buffers may be inefficient; dynamic allocation risks fragmentation; simultaneous access causes corruption.
  4. Final Answer:

    Declare a static buffer globally and call vTaskList() inside a mutex-protected function -> Option D
  5. Quick Check:

    Global buffer + mutex = safe vTaskList() usage [OK]
Hint: Use global buffer with mutex to avoid concurrent corruption [OK]
Common Mistakes:
  • Calling vTaskList() concurrently on same buffer
  • Using local buffers without synchronization
  • Freeing buffer too soon after vTaskList() call
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard