The vTaskList() function helps you see what tasks are running in FreeRTOS. It shows their names, states, priorities, and stack usage. This is useful to understand how your program is working.
vTaskList() for task status dump in FreeRTOS
void vTaskList(char *pcWriteBuffer);
pcWriteBuffer must point to a buffer large enough to hold the task list string.
The output is a formatted string showing task name, state, priority, stack, and task number.
vTaskList() to fill it, then prints the task list.char taskListBuffer[512]; vTaskList(taskListBuffer); printf("Task List:\n%s", taskListBuffer);
// Edge case: Empty task list (no tasks created yet) char emptyBuffer[512]; vTaskList(emptyBuffer); printf("Empty Task List:\n%s", emptyBuffer);
// Edge case: Single task char singleTaskBuffer[512]; vTaskList(singleTaskBuffer); printf("Single Task List:\n%s", singleTaskBuffer);
// Edge case: Task at highest priority char highPriorityBuffer[512]; vTaskList(highPriorityBuffer); printf("High Priority Task List:\n%s", highPriorityBuffer);
This program creates two simple tasks with different priorities. It starts the FreeRTOS scheduler. After scheduler stops (which normally doesn't happen), it calls vTaskList() to get the task status and prints it.
#include "FreeRTOS.h" #include "task.h" #include <stdio.h> // Simple task function void vSimpleTask(void *pvParameters) { for (;;) { vTaskDelay(pdMS_TO_TICKS(1000)); } } int main(void) { // Create two tasks xTaskCreate(vSimpleTask, "Task1", 1000, NULL, 1, NULL); xTaskCreate(vSimpleTask, "Task2", 1000, NULL, 2, NULL); // Buffer to hold task list char taskListBuffer[512]; // Start scheduler vTaskStartScheduler(); // This code runs only if scheduler exits (which normally it doesn't) vTaskList(taskListBuffer); printf("Task List:\n%s", taskListBuffer); return 0; }
Time complexity: vTaskList() runs in O(n) where n is the number of tasks.
Space complexity: The buffer size must be large enough to hold all task info; typically 512 bytes or more.
Common mistake: Not providing a large enough buffer causes truncated or corrupted output.
When to use: Use vTaskList() for debugging and monitoring task states. For real-time monitoring, consider other methods as this function is not real-time safe.
vTaskList() shows all running tasks and their status in a readable format.
It requires a buffer to store the output string.
Useful for debugging and checking task health in FreeRTOS.