MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / list_process

Function list_process

components/lwp/lwp_pid.c:1757–1834  ·  view source on GitHub ↗

* @brief Lists all processes and threads in the system * * @return long Returns 0 on success * * @note This function: * - Prints a header with process/thread information columns * - Lists all kernel threads (without LWP association) * - Lists all user processes (LWPs) with their threads * - For each thread, displays: * - PID/TID (process/thread IDs) *

Source from the content-addressed store, hash-verified

1755 * - Thread name/command
1756 */
1757long list_process(void)
1758{
1759 int index;
1760 int maxlen;
1761 rt_ubase_t level;
1762 struct rt_thread *thread;
1763 struct rt_list_node *node, *list;
1764 const char *item_title = "thread";
1765
1766 int count = 0;
1767 struct rt_thread **threads;
1768
1769 maxlen = RT_NAME_MAX;
1770#ifdef RT_USING_SMP
1771 rt_kprintf("%-*.s %-*.s %-*.s cpu pri status sp stack size max used left tick error %-*.s\n", 4, "PID", 4, "TID", maxlen, item_title, maxlen, "cmd");
1772 object_split(4);rt_kprintf(" ");object_split(4);rt_kprintf(" ");object_split(maxlen);rt_kprintf(" ");
1773 rt_kprintf( "--- --- ------- ---------- ---------- -------- ---------- -----");rt_kprintf(" ");object_split(maxlen);rt_kprintf("\n");
1774#else
1775 rt_kprintf("%-*.s %-*.s %-*.s pri status sp stack size max used left tick error\n", 4, "PID", 4, "TID", maxlen, item_title, maxlen, "cmd");
1776 object_split(4);rt_kprintf(" ");object_split(4);rt_kprintf(" ");object_split(maxlen);rt_kprintf(" ");
1777 rt_kprintf( "--- ------- ---------- ---------- -------- ---------- -----");rt_kprintf(" ");object_split(maxlen);rt_kprintf("\n");
1778#endif /*RT_USING_SMP*/
1779
1780 count = rt_object_get_length(RT_Object_Class_Thread);
1781 if (count > 0)
1782 {
1783 /* get thread pointers */
1784 threads = (struct rt_thread **)rt_calloc(count, sizeof(struct rt_thread *));
1785 if (threads)
1786 {
1787 index = rt_object_get_pointers(RT_Object_Class_Thread, (rt_object_t *)threads, count);
1788
1789 if (index > 0)
1790 {
1791 for (index = 0; index <count; index++)
1792 {
1793 struct rt_thread th;
1794
1795 thread = threads[index];
1796
1797 level = rt_spin_lock_irqsave(&thread->spinlock);
1798 if ((rt_object_get_type(&thread->parent) & ~RT_Object_Class_Static) != RT_Object_Class_Thread)
1799 {
1800 rt_spin_unlock_irqrestore(&thread->spinlock, level);
1801 continue;
1802 }
1803
1804 rt_memcpy(&th, thread, sizeof(struct rt_thread));
1805 rt_spin_unlock_irqrestore(&thread->spinlock, level);
1806
1807 if (th.lwp == RT_NULL)
1808 {
1809 rt_kprintf(" %-*.*s ", maxlen, RT_NAME_MAX, "kernel");
1810 print_thread_info(&th, maxlen);
1811 }
1812 }
1813 }
1814 rt_free(threads);

Callers

nothing calls this directly

Calls 12

rt_kprintfFunction · 0.85
rt_object_get_lengthFunction · 0.85
rt_callocFunction · 0.85
rt_object_get_pointersFunction · 0.85
rt_object_get_typeFunction · 0.85
rt_memcpyFunction · 0.85
print_thread_infoFunction · 0.85
rt_freeFunction · 0.85
lwp_to_pidFunction · 0.85
object_splitFunction · 0.70
rt_spin_lock_irqsaveFunction · 0.50

Tested by

no test coverage detected