Announcement

Collapse
No announcement yet.

Listing process by CPU

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Listing process by CPU

    Hello,
    Does anyone know a way to sort running process by what CPU they are running on? For example in our environment, we have servers with many cores / cpus, and our monitoring will pull up alerts saying something along the lines of

    Server Name - CPU 7 - High utilization (99%)

    The only problem is that I dont know how to tell which of the process using alot of CPU are tied to CPU 7.

    I cant find an option in task manager or process explorer to list what CPU the process is using. I have also explored the properties of the powershell class get-process and WMI Win32_Process. Cant find a CPU identifier for individual processes running.

    Appreciate any help.

  • #2
    Re: Listing process by CPU

    Hi,

    Which Windows version are you running?

    Comment


    • #3
      Re: Listing process by CPU

      Hi,

      probably you need to look into mom/scom. they will provide you performance rules and alerts for cpu cores.
      Thanks & Regards
      v-2nas

      MCTS 2008, MCTIP, MCSE 2003, MCSA+Messaging E2K3, MCP, E2K7
      Sr. Wintel Eng. (Investment Bank)
      Independent IT Consultant and Architect
      Blog: http://www.exchadtech.blogspot.com

      Show your appreciation for my help by giving reputation points

      Comment


      • #4
        Re: Listing process by CPU

        Mostly I am working with windows 2003 32 bit and 64 bit servers. A few windows 2008.

        Unfortunately I dont have MoM/SCOM to use. But if MoM and SCOM are able to gather this info, there must be a WMI call or something similar to get the info of processes tied to each CPU.

        Comment


        • #5
          Re: Listing process by CPU

          Use Process Explorer from sysinternal site. This little stand alone tool can show you what process and threads are eating up your CPU or memory.

          Read the help file and get acquainted with the tool. You will find the root cause of it.

          Let me know in case of anything.

          Comment


          • #6
            Re: Listing process by CPU

            This one is a tough nut. If you suspect a runaway process, you might start it with specific affinity in the first hand. A Howtogeek article explains more, but the method for starting Notepad and tying it for CPU 1 works like so,

            c:\windows\system32\cmd.exe /C start /affinity 1 notepad.exe

            There are API calls like SetProcessAffinityMask() and GetProcessAffinityMask() in the Win32 API, but right now I don't have time to whack up an example.

            Here is a Powershell oneliner that lists all the processes and their CPU affinities:

            Get-Process | % { write-host $( "{0}: {1}" -f $_.name, ([System.Diagnostics.Process]::GetProcessById($_.Id)).ProcessorAffinity) }

            -vP

            Comment


            • #7
              Re: Listing process by CPU

              Appreciate the responses.
              @jainal - I have tried Process Explorer, but unfortunately it does not break out process by CPU

              @vonPryz - Thank you for the "one liner" - While the script runs, the output shows each process shows either a blank processor affinity or a processor affinity of 65535.
              In other words on a machine with 8 processors I only see one processor affinity (or a blank line) next to each process in the output of the script. I have tested this on both physical and virtual machines.

              Any ideas?

              I have tried playing with the ProcessorAffininty property of get-process.. but I am not a scripter and have only basic knowledge.

              Would this question be better suited in the scripting forum section?

              Comment


              • #8
                Re: Listing process by CPU

                Why are you coloring your text differently, and line by line nonetheless?
                ** Remember to give credit where credit is due and leave reputation points where appropriate **

                Comment


                • #9
                  Re: Listing process by CPU

                  Originally posted by Wired View Post
                  Why are you coloring your text differently, and line by line nonetheless?

                  no reason, not even sure why its colored differently. Probably due to my copy and paste job out of my text editor / spell checker

                  Comment


                  • #10
                    Re: Listing process by CPU

                    Try it like this:
                    Get-Process | % { write-host $( "{0}: {1}" -f $_.name, ([System.Diagnostics.Process]::GetProcessById($_.Id).ProcessorAffinity)) }

                    I think there was a misplaced bracket earlier

                    Gives apparently valid results on my 2003 and 2008 boxes, although all processes appear to run on one core
                    Tom Jones
                    MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
                    PhD, MSc, FIAP, MIITT
                    IT Trainer / Consultant
                    Ossian Ltd
                    Scotland

                    ** Remember to give credit where credit is due and leave reputation points where appropriate **

                    Comment


                    • #11
                      Re: Listing process by CPU

                      @Ossian

                      Still no luck. I tried this script on some phyiscal and virtual 2003 boxes, and still seeing either one processor affinity or blank entries next to each process. Im not sure why it would show that if I have multiple processors on each of these boxes.
                      Appreciate the help.

                      Comment


                      • #12
                        Re: Listing process by CPU

                        Originally posted by Jlewko View Post
                        output shows each process shows either a blank processor affinity or a processor affinity of 65535.
                        That is because you have not set processor affinity for any process. In such a case, the OS is free to schedule process to any CPU. Thus the affinity mask is large a number. In my dual-core laptop, the affinities are 1 (core 0), 2 (core 1) and 3 (both cores).

                        What you need to do is to set 1/2 of your suspected processes to have CPU affinity to some cores and the rest to other cores. Either specify the affinity on command line or use the task manager.

                        Start looking for a CPU with high usage. When you have found one, split the group that is assigned to that CPU again in half and assign CPU affinities. and so on, untill you find the runaway process. This is called binary search; you reduce the suspect process group size by 50% each time, so the culprit should be found with not too much trouble.

                        -vP

                        Comment


                        • #13
                          Re: Listing process by CPU

                          VonPryz,
                          Not sure I understand. Just now I was on a server with 8 processors. In task manager, on the performance tab, I could see 2 of 8 the processors were spiked and consistent at 100% cpu used. while the other processors were at normal usage.

                          When running the powershell commands you provided, I did get a list of processes, but they all were listed as the same CPU.

                          I did not setup any cpu affinity ahead of time like you had mentioned, as these are production boxes (the issue isnt critical at current) that I would like to not make any changes too if possible.

                          In this case I was able to pinpoint the process spiking the CPUs because it was the only process using up a lot of CPU (process tab of task manager).

                          Hope I am coming across clear. If there is something else I can try / research, would appreciate any info. Unfortunately I dont have the information on how our monitoring is able to pull its information (closed vendor proprietary info).

                          Comment


                          • #14
                            Re: Listing process by CPU

                            Hi,

                            I checked perfmon, it does show process and processor (cores..it's called instances under perfmon) but it doesn't excalty says which cpu core a process is binded to.. seems like it's not possible natively in windows OS unless we have some kind of monitoring tool.

                            Ok..... One another way is to take a dump of the process using adplus (although it's used for crash/hang but you can do it for spiking process) and then use kernel debugger app. windbg and then you can check out the complete history
                            Last edited by v-2nas; 13th January 2011, 20:27. Reason: moreinfo
                            Thanks & Regards
                            v-2nas

                            MCTS 2008, MCTIP, MCSE 2003, MCSA+Messaging E2K3, MCP, E2K7
                            Sr. Wintel Eng. (Investment Bank)
                            Independent IT Consultant and Architect
                            Blog: http://www.exchadtech.blogspot.com

                            Show your appreciation for my help by giving reputation points

                            Comment

                            Working...
                            X