Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all process of current active session

I have a small problem while developing an application. I want to access all process of the current session only. Currently I am using Process class but it will return all process of all session.

Please help me to get process of the current active session only not all.

Help needed to solve the problem.

like image 355
Awadhendra Avatar asked Oct 21 '11 11:10

Awadhendra


1 Answers

This will give you a list of the process running that are running with the same sessionID as the current process. I think that is what you want.

Process[] runningProcesses = Process.GetProcesses();
var currentSessionID = Process.GetCurrentProcess().SessionId;

Process[] sameAsThisSession =
    runningProcesses.Where(p => p.SessionId == currentSessionID).ToArray();

foreach (var p in sameAsthisSession)
{
   Trace.WriteLine(p.ProcessName); 
}
like image 111
John Sobolewski Avatar answered Oct 20 '22 07:10

John Sobolewski