2021-01-15 16:18 CET

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0000049Frama-CPlug-in > jessiepublic2009-06-23 18:03
Reporterdpariente 
Assigned Tocmarche 
PrioritynormalSeveritymajorReproducibilityalways
StatusclosedResolutionfixed 
Product Version 
Target VersionFixed in VersionFrama-C Beryllium-20090601-beta1 
Summary0000049: Jessie/Gwhy: cpulimit-win.c
DescriptionHello,

The release of cpulimit-win.c currently distributed is not the good one but an old one: it does not take into account exit code from process.
A second version was forwarded by email (on 12/07/08) correcting this bug. Please find it enclosed!

Best regards,
Dillon
TagsNo tags attached.
Attached Files
  • c file icon cpulimit-win.c (2,746 bytes) 2009-04-11 16:37 -
    /**************************************************************************/
    /*                                                                        */
    /*  Copyright (C) 2008                                                    */
    /*    Dillon PARIENTE                                                     */
    /*                                                                        */
    /*  This software is free software; you can redistribute it and/or        */
    /*  modify it under the terms of the GNU Library General Public           */
    /*  License version 2, with the special exception on linking              */
    /*  described in file LICENSE.                                            */
    /*                                                                        */
    /*  This software is distributed in the hope that it will be useful,      */
    /*  but WITHOUT ANY WARRANTY; without even the implied warranty of        */
    /*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                  */
    /*                                                                        */
    /**************************************************************************/
    
    #include <windows.h>
    #include <stdio.h>
    #include <errno.h>
    
    int main( int argc, char *argv[] )
    {
    STARTUPINFO si;
    PROCESS_INFORMATION pi;
    int i;
    unsigned ex;
    unsigned long s=0;	// length of args after concat
    char * p;			// command line parameter
    ZeroMemory( &si, sizeof(si) );
    si.cb = sizeof(si);
    ZeroMemory( &pi, sizeof(pi) );
    
    if( argc < 3 ){
    	printf("Usage: %s <time limit in seconds> <command>\n", argv[0]);
        return -1;
    }
    
    // concats argv[2..] into a single command line parameter
    for(i=2;i<argc;i++) s+=strlen(argv[i])+1;
    if (s>32767) { // CreateProcess does not allow more than 32767 bytes for command line parameter
    	printf("%s: Error: parameter's length exceeds CreateProcess limits\n", argv[0]);
        return -1;
    }
    p=(char*)malloc(s);
    if (p==NULL) {
    	printf("%s: Error: when allocating %d bytes in memory\n", argv[0], (int)s);
        return -1;
    }
    for(i=2;i<argc;i++) {strncat(p,argv[i],strlen(argv[i])); if(i<argc-1)strcat(p," ");}
    
    // launches "child" process with command line parameter
    if( !CreateProcess(NULL, p, NULL, NULL, FALSE,0, NULL, NULL, &si, &pi) ){
        printf( "%s: Error: failed when launching <%s>\n", argv[0], p);
        return -1;
    }
    
    // waits, terminates and frees handles and malloc
    WaitForSingleObject( pi.hProcess, 1000*atoi(argv[1]) );
    TerminateProcess(pi.hProcess,10);
    GetExitCodeProcess(pi.hProcess,(LPDWORD)&ex);
    CloseHandle( pi.hProcess );
    CloseHandle( pi.hThread );
    free(p);
    
    return ex;
    }
    
    // How to compile under Cygwin (needs make, gcc and win32api):
    // 		gcc -Wall -o cpulimit cpulimit.c
    
    c file icon cpulimit-win.c (2,746 bytes) 2009-04-11 16:37 +

-Relationships
+Relationships

-Notes

~0000088

cmarche (developer)

fixed in why
+Notes

-Issue History
Date Modified Username Field Change
2009-04-11 16:37 dpariente New Issue
2009-04-11 16:37 dpariente File Added: cpulimit-win.c
2009-04-17 17:53 signoles Status new => assigned
2009-04-17 17:53 signoles Assigned To => cmarche
2009-05-22 16:02 cmarche Note Added: 0000088
2009-05-22 16:02 cmarche Status assigned => resolved
2009-05-22 16:02 cmarche Resolution open => fixed
2009-06-23 18:02 signoles Status resolved => closed
2009-06-23 18:03 signoles Fixed in Version => Frama-C Beryllium beta-1
+Issue History