Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Check if a process, session or task is currently active
ResourceFunction["ProcessRunningQ"][patt] gives True if there are any processes running on your computer system whose names match the string pattern patt. | |
ResourceFunction["ProcessRunningQ"][prop→val] gives True if there are any processes for which property prop has value val. | |
ResourceFunction["ProcessRunningQ"][<|prop1→val1,…|>] gives True if there are any processes for which property propi has value vali. |
pid | an Integer corresponding to a process ID |
ProcessObject[…] | a system process represented as a ProcessObject |
TaskObject[…] | a background task |
CloudObject[…] | a ScheduledTask deployed to the cloud |
WebSessionObject[…] | the underlying process used by the WebSessionObject |
ExternalSessionObject[…] | the underlying process used by the ExternalSessionObject |
KernelObject[…] | the link for communicating with the given subkernel |
LinkObject[…] | a LinkObject |
InputStream[…] | an input stream |
OutputStream[…] | an output stream |
"PID" | process ID |
"PPID" | parent process ID |
"Memory" | memory the process is using |
"StartTime" | date the process was started |
"RealTime" | time since the process started |
"SystemTime" | CPU time spent in kernel space |
"UserTime" | CPU time spent in user space |
"Threads" | number of threads |
"User" | the user the process belongs to |
"Program" | name of the program |
"Path" | full file path of the program |
Check if a process is currently running using a process ID:
In[1]:= |
Out[1]= |
Check if a process is running by name (results may be platform-dependent):
In[2]:= |
Out[2]= |
In[3]:= |
Out[3]= |
In[4]:= |
Out[4]= |
Check if a ProcessObject is running:
In[5]:= |
Out[5]= |
In[6]:= |
Out[6]= |
Close the process:
In[7]:= |
Verify that it’s no longer running:
In[8]:= |
Out[8]= |
Check if a TaskObject is running:
In[9]:= |
Out[9]= |
In[10]:= |
Out[10]= |
Check again after it has finished:
In[11]:= |
Out[11]= |
Check if a stream is open:
In[12]:= |
Out[12]= |
In[13]:= |
Out[13]= |
In[14]:= |
Out[14]= |
In[15]:= |
Out[15]= |
Use string patterns:
In[16]:= |
Out[16]= |
In[17]:= |
Out[17]= |
Use an association of properties:
In[18]:= |
Out[18]= |
In[19]:= |
Out[19]= |
Check if a scheduled task deployed to the cloud is currently following its assigned schedule:
In[20]:= |
Out[20]= |
In[21]:= |
Out[21]= |
A task is not considered to be running if it is suspended:
In[22]:= |
Out[22]= |
In[23]:= |
Out[23]= |
TaskResume the task:
In[24]:= |
Out[24]= |
In[25]:= |
Out[25]= |
In[26]:= |
Out[26]= |
Check if a WebSessionObject is running:
In[27]:= |
Out[27]= |
In[28]:= |
Out[28]= |
Close the session using DeleteObject:
In[29]:= |
Verify that it’s no longer running:
In[30]:= |
Out[30]= |
Check if an ExternalSessionObject is running:
In[31]:= |
Out[31]= |
In[32]:= |
Out[32]= |
Close the session using DeleteObject:
In[33]:= |
Verify that it’s no longer running:
In[34]:= |
Out[34]= |
Check that parallel subkernels are still running:
In[35]:= |
Out[35]= |
In[36]:= |
Out[36]= |
Close one of the kernels:
In[37]:= |
Out[37]= |
Verify that one of the kernels is no longer running:
In[38]:= |
Out[38]= |
Check that a LinkObject is still running (this example requires the ability to launch new kernels with LinkLaunch on the current machine):
In[39]:= |
Out[39]= |
In[40]:= |
Out[40]= |
Get the $ProcessID of the linked kernel:
In[41]:= |
Out[41]= |
In[42]:= |
Out[24]= |
In[43]:= |
Out[43]= |
In[44]:= |
Out[44]= |
Check that it’s running by using the PID:
In[45]:= |
Out[45]= |
Close the link using LinkClose:
In[46]:= |
Verify that it’s no longer running:
In[47]:= |
Out[47]= |
Check using the PID:
In[48]:= |
Out[48]= |
Processes do not need to be started by the current kernel:
In[49]:= |
Out[49]= |
In[50]:= |
Out[50]= |
Use the PID of a random system process:
In[51]:= |
Out[51]= |
In[52]:= |
Out[52]= |
When patt is a string pattern, ProcessRunningQ[patt] is equivalent to MatchQ[SystemProcesses[patt],{__ProcessObject}]:
In[53]:= |
Out[53]= |
In[54]:= |
Out[54]= |
The same is true for rules:
In[55]:= |
Out[55]= |
In[56]:= |
Out[56]= |
A LinkObject may still be reported as running if it appears in Links[] even if the connected process has been terminated:
In[57]:= |
Out[57]= |
Get the PID:
In[58]:= |
Out[58]= |
In[59]:= |
Out[42]= |
In[60]:= |
Out[60]= |
In[61]:= |
Out[61]= |
Get the corresponding ProcessObject:
In[62]:= |
Out[62]= |
Terminate the process with KillProcess instead of LinkClose:
In[63]:= |
The LinkObject is still active:
In[64]:= |
Out[64]= |
In[65]:= |
Out[65]= |
In[66]:= |
Out[66]= |
However, the process itself is not:
In[67]:= |
Out[67]= |
This work is licensed under a Creative Commons Attribution 4.0 International License