Managing processes and sessions is essential for optimizing and monitoring your 4D applications. You can easily manipulate and retrieve crucial information about these elements thanks to different commands.
With 4D 20 R7, we are pleased to announce a series of enhancements that make these functions even more accessible and effective. These new features are designed not only to simplify your work, but also to boost the performance of your code. The improvements include:
- Getting the process info in an object to make it easier to manipulate the properties,
- Allowing direct access to session info using a session ID for easier management,
- Making it easier to get a process number directly from its ID,
- Accessing the creation date of a process
- Optimized filtering of the results returned by the Process activity command to obtain all processes in a session.
Find out how these updates can transform your development experience and improve the efficiency of your applications!
HDI: Process properties, Session properties, and Process activity in action
Retrieve the info for a process or a session
New Process info command
The new Process info command returns an object. The advantage of this syntax comes from its ability to retrieve the info in an object, making them easier to handle than using multiple variables. So, the _O_PROCESS PROPERTIES command has been deprecated.
var $process : Object
$process:=Process info($processNumber)
The Process info command returns a new property, creationDateTime. This property lets you find out when a process was created.
Example output:
{
"number": 4,
"name": "Application process",
"sessionID": "3C81A8D7AFE64C2E9CCFFCDC35DC52F5",
"ID": 4,
"visible": true,
"type": -18,
"state": 0,
"creationDateTime": "2024-09-22T12:46:39.243Z",
"preemptive": false,
"systemID": "123145476132864",
"cpuUsage": 0,
"cpuTime": 0.006769
}
For example, to know if my process is preemptive:
var $preemptive : Boolean
$preemptive:=Process info($processNumber).preemptive
New Session info command
The new Session info command lets you retrieve the info of a session using its sessionID. You could already retrieve this information with the Process activity command. The advantage of this new command is that it returns a simple object, saving time and performance.
var $session : Object
$session:=Session info($sessionID)
$session:=Session info(Process info($processNumber).sessionID)
Example output:
{ "ID": "3C81A8D7AFE64C2E9CCFFCDC35DC52F5", "userName": "Designer", "machineName": "My Computer", "systemUserName": "John Doe", "IPAddress": "localhost", "hostType": "mac", "type": "remote", "state": "active", "creationDateTime": "2024-09-10T09:55:54Z", "persistentID": "8FFDAE519F1F4DCDB81E8E8DB00AD101" }
Retrieve process number from process ID
The Process number command has been updated. It is now possible to pass the process ID to retrieve the process number directly, in addition to the previous method of using the process name.
var $processNumber : Integer
var $processName : Text
var $processID : Integer
// From process name
$processNumber:=Process number($processName)
// From process ID
$processNumber:=Process number($processID)
Improvement for Process activity command
Filter processes by session
The Process activity command lets you retrieve the list of processes and sessions. If you pass the Processes only or Sessions only option, you retrieve either the list of processes or the list of sessions. Now, you can filter your results more efficiently. Just pass a session ID to retrieve the list of the processes linked to the session.
Here are the different possible combinations:
// return all sessions and processes
$o:=Process activity()
// return all processes
$o:=Process activity(Processes only)
// return all sessions
$o:=Process activity(Sessions only)
// return the session passed in parameter and all linked processes
$o:=Process activity($sessionID)
// return all processes linked to the session passed in parameter
$o:=Process activity($sessionID ; Processes only)
// return the session passed in parameter
$o:=Process activity($sessionID ; Sessions only)
Retrieve the creation date of a process
The new property, creationDateTime, has also been added to the Process object returned by the Process activity command. So, you can easily retrieve the creation date of any process.
Example output:
{
"processes": [
{
"name": "Application process",
"sessionID": "3C81A8D7AFE64C2E9CCFFCDC35DC52F5",
"number": 4,
"ID": 4,
"visible": true,
"systemID": "123145476132864",
"type": -18,
"state": 0,
"cpuUsage": 0,
"cpuTime": 0.006769,
"creationDateTime": "2024-09-22T12:46:39.324Z",
"preemptive": false
}
]
}
Dive Deeper
For more details on these exciting changes, please check out the updated documentation on these commands. We can’t wait to hear your thoughts, join the conversation on our forum!