File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change
1
+ import subprocess
1
2
from models .process import Process
2
3
3
4
@@ -323,6 +324,30 @@ def create_fake_processes(self) -> None:
323
324
)
324
325
)
325
326
327
+ def count_active_terminals ():
328
+ try :
329
+ # Run 'who' to get active login sessions
330
+ result = subprocess .run (
331
+ ["who" ], stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True
332
+ )
333
+
334
+ if result .returncode != 0 :
335
+ raise RuntimeError (f"Error running 'who': { result .stderr } " )
336
+
337
+ lines = result .stdout .strip ().split ("\n " )
338
+
339
+ # Extract terminals from the output (2nd column)
340
+ terminals = [line .split ()[1 ] for line in lines if line ]
341
+
342
+ # Remove duplicates, in case multiple sessions use the same terminal
343
+ unique_terminals = set (terminals )
344
+
345
+ return len (unique_terminals )
346
+
347
+ except Exception as e :
348
+ print (f"Error checking active terminals: { e } " )
349
+ return 0
350
+
326
351
def add_process (self , process : Process ) -> None :
327
352
"""Add a new process to the process group."""
328
353
if process .pid in self .processes :
You can’t perform that action at this time.
0 commit comments