CPU usage program

Discussion in 'C++' started by Sethu, Oct 8, 2007.

  1. Sethu

    Sethu Guest

    Hi everybody,

    Can anyone give me a simple program which would consumes more CPU
    usage (more than 50%) in windows?

    Thanks,
    Sethu
     
    Sethu, Oct 8, 2007
    #1
    1. Advertisements

  2. On 2007-10-08 17:16, Sethu wrote:
    > Hi everybody,
    >
    > Can anyone give me a simple program which would consumes more CPU
    > usage (more than 50%) in windows?


    int main()
    {
    while (true) {}
    }

    I welcome anyone to write a smaller one.

    Of course, this will never consume more than 50% CPU on a multi-core
    system, but you can always run more instances of it.

    --
    Erik Wikström
     
    =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=, Oct 8, 2007
    #2
    1. Advertisements

  3. Sethu

    Zeppe Guest

    Erik Wikström wrote:
    > On 2007-10-08 17:16, Sethu wrote:
    >> Hi everybody,
    >>
    >> Can anyone give me a simple program which would consumes more CPU
    >> usage (more than 50%) in windows?

    >
    > int main()
    > {
    > while (true) {}
    > }
    >
    > I welcome anyone to write a smaller one.


    int main(){for(;;);}

    Regards,

    Zeppe
     
    Zeppe, Oct 8, 2007
    #3
  4. Erik Wikström wrote:
    > On 2007-10-08 17:16, Sethu wrote:
    >> Hi everybody,
    >>
    >> Can anyone give me a simple program which would consumes more CPU
    >> usage (more than 50%) in windows?

    >
    > int main()
    > {
    > while (true) {}
    > }
    >
    > I welcome anyone to write a smaller one.


    Yours:
    int main(){while(true){}}

    Mine:
    int main(){while(1);}

    Zeppe's:
    int main(){for(;;);}

    At least 4 and 5 symbols smaller (respectively). :)

    > [..]


    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Oct 8, 2007
    #4
  5. Sethu

    Shadowman Guest

    Erik Wikström wrote:
    > On 2007-10-08 17:16, Sethu wrote:
    >> Hi everybody,
    >>
    >> Can anyone give me a simple program which would consumes more CPU
    >> usage (more than 50%) in windows?

    >
    > int main()
    > {
    > while (true) {}
    > }
    >
    > I welcome anyone to write a smaller one.
    >

    int main() {main();}

    > Of course, this will never consume more than 50% CPU on a multi-core
    > system, but you can always run more instances of it.
    >



    --
    SM
    rot13 for email
     
    Shadowman, Oct 8, 2007
    #5
  6. Sethu

    Rolf Magnus Guest

    Shadowman wrote:

    > Erik Wikström wrote:
    >> On 2007-10-08 17:16, Sethu wrote:
    >>> Hi everybody,
    >>>
    >>> Can anyone give me a simple program which would consumes more CPU
    >>> usage (more than 50%) in windows?

    >>
    >> int main()
    >> {
    >> while (true) {}
    >> }
    >>
    >> I welcome anyone to write a smaller one.
    >>

    > int main() {main();}


    This should produce a compile error. Calling main within your program is
    forbidden.
     
    Rolf Magnus, Oct 8, 2007
    #6
  7. On Oct 8, 12:33 pm, Rolf Magnus <> wrote:
    > Shadowman wrote:
    > > Erik Wikström wrote:
    > >> On 2007-10-08 17:16, Sethu wrote:
    > >>> Hi everybody,

    >
    > >>> Can anyone give me a simple program which would consumes more CPU
    > >>> usage (more than 50%) in windows?

    >
    > >> int main()
    > >> {
    > >> while (true) {}
    > >> }

    >
    > >> I welcome anyone to write a smaller one.

    >
    > > int main() {main();}

    >
    > This should produce a compile error. Calling main within your program is
    > forbidden.


    Can you cite chapter and verse? I'm not criticizing what you're
    saying... I'd just like official verification of it.
     
    Justin Spahr-Summers, Oct 8, 2007
    #7
  8. Justin Spahr-Summers wrote:
    > On Oct 8, 12:33 pm, Rolf Magnus <> wrote:
    >> Shadowman wrote:
    >>> Erik Wikström wrote:
    >>>> On 2007-10-08 17:16, Sethu wrote:
    >>>>> Hi everybody,

    >>
    >>>>> Can anyone give me a simple program which would consumes more CPU
    >>>>> usage (more than 50%) in windows?

    >>
    >>>> int main()
    >>>> {
    >>>> while (true) {}
    >>>> }

    >>
    >>>> I welcome anyone to write a smaller one.

    >>
    >>> int main() {main();}

    >>
    >> This should produce a compile error. Calling main within your
    >> program is forbidden.

    >
    > Can you cite chapter and verse? I'm not criticizing what you're
    > saying... I'd just like official verification of it.


    [basic.start.main]/3 begins with words "The function main shall
    not be used (3.2) within a program."

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Oct 8, 2007
    #8
  9. On 2007-10-08 23:00, Justin Spahr-Summers wrote:
    > On Oct 8, 12:33 pm, Rolf Magnus <> wrote:
    >> Shadowman wrote:
    >> > Erik Wikström wrote:
    >> >> On 2007-10-08 17:16, Sethu wrote:
    >> >>> Hi everybody,

    >>
    >> >>> Can anyone give me a simple program which would consumes more CPU
    >> >>> usage (more than 50%) in windows?

    >>
    >> >> int main()
    >> >> {
    >> >> while (true) {}
    >> >> }

    >>
    >> >> I welcome anyone to write a smaller one.

    >>
    >> > int main() {main();}

    >>
    >> This should produce a compile error. Calling main within your program is
    >> forbidden.

    >
    > Can you cite chapter and verse? I'm not criticizing what you're
    > saying... I'd just like official verification of it.


    [basic.start.main]/3 "The function main shall not be used within a program."

    --
    Erik Wikström
     
    =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=, Oct 8, 2007
    #9
  10. On 2007-10-08 18:35, Victor Bazarov wrote:
    > Erik Wikstr�m wrote:
    >> On 2007-10-08 17:16, Sethu wrote:
    >>> Hi everybody,
    >>>
    >>> Can anyone give me a simple program which would consumes more CPU
    >>> usage (more than 50%) in windows?

    >>
    >> int main()
    >> {
    >> while (true) {}
    >> }
    >>
    >> I welcome anyone to write a smaller one.

    >
    > Yours:
    > int main(){while(true){}}
    >
    > Mine:
    > int main(){while(1);}
    >
    > Zeppe's:
    > int main(){for(;;);}
    >
    > At least 4 and 5 symbols smaller (respectively). :)


    Yes, I asked for that. Though I was thinking more in terms of the size
    of the executable.

    --
    Erik Wikström
     
    =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=, Oct 8, 2007
    #10
  11. Sethu

    UINDEX Guest

    On Oct 8, 11:16 pm, Sethu <> wrote:
    > Hi everybody,
    >
    > Can anyone give me a simple program which would consumes more CPU
    > usage (more than 50%) in windows?
    >
    > Thanks,
    > Sethu


    this is a sample program which can consume one core.
    call OnTest N(CPU number) times to consumes more CPU usage (more than
    50%).

    DWORD WINAPI UseOneCore(void * p)
    {
    while(true);
    return 0;
    }


    void CMy00Dlg::OnTest()
    {
    ::CreateThread(NULL,0,UseOneCore,NULL,0,NULL);
    }
     
    UINDEX, Oct 9, 2007
    #11
  12. Sethu

    Zeppe Guest

    Erik Wikström wrote:
    > On 2007-10-08 23:00, Justin Spahr-Summers wrote:
    >> On Oct 8, 12:33 pm, Rolf Magnus <> wrote:
    >>> Shadowman wrote:
    >>>> Erik Wikström wrote:
    >>>>> On 2007-10-08 17:16, Sethu wrote:
    >>>>>> Hi everybody,
    >>>>>> Can anyone give me a simple program which would consumes more CPU
    >>>>>> usage (more than 50%) in windows?
    >>>>> int main()
    >>>>> {
    >>>>> while (true) {}
    >>>>> }
    >>>>> I welcome anyone to write a smaller one.
    >>>> int main() {main();}
    >>> This should produce a compile error. Calling main within your program is
    >>> forbidden.

    >> Can you cite chapter and verse? I'm not criticizing what you're
    >> saying... I'd just like official verification of it.

    >
    > [basic.start.main]/3 "The function main shall not be used within a program."
    >

    Restated also in [expr.call]/9: Recursive calls are permitted, except to
    the function named main (3.6.1).

    Regards,

    Zeppe
     
    Zeppe, Oct 9, 2007
    #12
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vijay Ram

    How to fetch CPU Usage from DOT Net

    Vijay Ram, Sep 8, 2003, in forum: ASP .Net
    Replies:
    5
    Views:
    5,358
    Fergus Cooney
    Sep 22, 2003
  2. Vivek
    Replies:
    1
    Views:
    1,477
  3. Davy

    Control CPU usage of a program?

    Davy, Aug 21, 2005, in forum: C Programming
    Replies:
    6
    Views:
    1,477
    HalleHamar
    Nov 4, 2012
  4. Robert
    Replies:
    3
    Views:
    518
    Chris Hills
    Aug 21, 2005
  5. hvt
    Replies:
    0
    Views:
    1,399
  6. hvt
    Replies:
    0
    Views:
    1,743
  7. CPU usage program

    , Oct 8, 2007, in forum: C Programming
    Replies:
    14
    Views:
    791
    Peter Pichler
    Oct 15, 2007
  8. pavunkumar

    How , system cpu and user cpu times calculates

    pavunkumar, Feb 27, 2009, in forum: C Programming
    Replies:
    1
    Views:
    504
Loading...