How to get the active task ID?

bonmot wrote on Wednesday, January 03, 2007:

I want to put a printf in one function to see which tasks are calling it.
So is there anyway to get the active task ID?
Thanks

Paul

nobody wrote on Wednesday, January 03, 2007:

extern void *pxCurrentTCB

might work if you linker will allow it - most will.  Other than that add a get function to task.c to return pxCurrentTCB, or pxCurrentTCB->uxTCBNumber for the current number, or even pxCurrenTCB->pcTaskName for the name of the current task.

Have fun :slight_smile:

Dave.

uxTaskGetTaskNumber(xTaskGetCurrentTaskHandle()) should work.

Hi @yakonoops ,
For the system reset this pxTCB->uxTaskNumber will it change for every system reset?

Task number is deterministic IF your task creation process is deterministic, i.e. you always create your tasks in exactly the same order.

The Task ID isn’t the best value for what you are looking to do, vTaskGetInfo to get the task name might be better, if you give every task a unique and stable name.

2 Likes