@@ -53,23 +53,24 @@ typedef bool (*activity_callback_t)(struct process_t* proc, void* opaque);
5353 * in a global doubly-linked list for scheduling.
5454 */
5555typedef struct process_t {
56- pid_t pid ; /**< Unique process ID */
57- pid_t ppid ; /**< Parent process ID */
58- process_state_t state ; /**< Running state */
59- time_t start_time ; /**< Start time (UNIX epoch) */
60- pid_t waitpid ; /**< PID being waited on */
61- cpu_id_t cpu ; /**< Logical CPU this process is assigned to */
62- const char * directory ; /**< Directory of program */
63- const char * name ; /**< Filename of program */
64- size_t size ; /**< Size of program in bytes */
65- const char * csd ; /**< Current selected directory */
66- struct basic_ctx * code ; /**< BASIC interpreter context */
67- struct process_t * sched_next ; /**< Next process in doubly linked list */
68- struct process_t * sched_prev ; /**< Previous process in doubly linked list */
69- struct process_t * global_next ; /**< Next process in doubly linked list */
70- struct process_t * global_prev ; /**< Previous process in doubly linked list */
71- activity_callback_t check_idle ; /**< If non-null, called to check if the process should remain idle */
72- void * idle_context ; /**< Opaque context passed to the check_idle callback */
56+ pid_t pid ; /**< Unique process ID */
57+ pid_t ppid ; /**< Parent process ID */
58+ process_state_t state ; /**< Running state */
59+ time_t start_time ; /**< Start time (UNIX epoch) */
60+ pid_t waitpid ; /**< PID being waited on */
61+ cpu_id_t cpu ; /**< Logical CPU this process is assigned to */
62+ const char * directory ; /**< Directory of program */
63+ const char * name ; /**< Filename of program */
64+ size_t size ; /**< Size of program in bytes */
65+ const char * csd ; /**< Current selected directory */
66+ struct basic_ctx * code ; /**< BASIC interpreter context */
67+ struct process_t * sched_next ; /**< Next process in doubly linked list */
68+ struct process_t * sched_prev ; /**< Previous process in doubly linked list */
69+ struct process_t * global_next ; /**< Next process in doubly linked list */
70+ struct process_t * global_prev ; /**< Previous process in doubly linked list */
71+ activity_callback_t check_idle ; /**< If non-null, called to check if the process should remain idle */
72+ void * idle_context ; /**< Opaque context passed to the check_idle callback */
73+ uint32_t cpu_percent ; /**< Rolling average CPU usage percentage */
7374} process_t ;
7475
7576/**
@@ -305,4 +306,31 @@ void proc_queue_dpc(dpc_t handler);
305306 */
306307void run_idles (uint8_t cpu );
307308
308- process_t * proc_load_anonymous (const char * source , pid_t parent_pid , const char * csd );
309+ /**
310+ * @brief Create and start an anonymous BASIC process from a source string
311+ *
312+ * This function creates a new process using the provided BASIC source code
313+ * rather than loading it from the filesystem. The process is initialised
314+ * and scheduled in the same way as one created via proc_load().
315+ *
316+ * @param source The BASIC program source code (must be valid and non-empty)
317+ * @param parent_pid The PID of the parent process
318+ * @param csd The current working directory to assign to the process
319+ *
320+ * @return Pointer to the newly created process on success, or NULL on failure
321+ */
322+ process_t * proc_load_anonymous (const char * source , pid_t parent_pid , const char * csd );
323+
324+ /**
325+ * @brief Get the averaged CPU usage percentage for a process
326+ *
327+ * Returns the rolling average CPU usage for the specified process as an
328+ * integer percentage in the range 0–100. A value of 0 indicates the process
329+ * is idle or waiting, while higher values indicate a greater share of CPU
330+ * time over the recent sampling window.
331+ *
332+ * @param pid The process ID to query
333+ *
334+ * @return CPU usage percentage for the process, or 0 if the PID is invalid
335+ */
336+ uint32_t proc_cpu_percent (pid_t pid );
0 commit comments