diff --git a/sites/cheerpx/src/content/docs/12-reference/20-CheerpX-linux-callbacks.md b/sites/cheerpx/src/content/docs/12-reference/20-CheerpX-linux-callbacks.md index 15587538..4ff18d2a 100644 --- a/sites/cheerpx/src/content/docs/12-reference/20-CheerpX-linux-callbacks.md +++ b/sites/cheerpx/src/content/docs/12-reference/20-CheerpX-linux-callbacks.md @@ -85,3 +85,32 @@ if (cx) { This example demonstrates how to register callbacks for CPU activity, disk activity, and disk latency. The CPU and disk activity callbacks log the current state (either "ready" or "busy") to the console, while the disk latency callback logs the latency of the last downloaded disk block. Additionally, the simulated events are generated for testing purposes, allowing you to see output for all three types of activity. + +### `processCreated` Event + +The `processCreated` event is triggered by the **CheerpX engine** whenever a native process is created. This includes actions such as running a command within the WebVM terminal. The event provides a mechanism to track the number of processes created during the session. + +**How it works** + +Here's how the `processCreated` event is utilized in the code: + +1. **Callback Registration:** + +During the initialization of the CheerpX environment, the event is registered with the callback `handleProcessCreated`. + +```js +cx.registerCallback("processCreated", handleProcessCreated); +``` + +2. **Callback implementation** + +The `handleProcessCreated` function increments a `processCount` variable and triggers a callback if one is set via the processCallback function. + +```js +function handleProcessCreated() { + processCount++; + if (processCallback) processCallback(processCount); +} +``` + +The purpose of the `processCreated` event is to maintain an up-to-date count of created processes. This information can be used to monitor system activity.