strange thing using Process class to call outside executable file

Discussion in 'ASP .Net' started by WangE, Nov 17, 2006.

  1. WangE

    WangE Guest

    I've been working on an online judge(for ACM/ICPC) using C#.Programmes
    submitted by users can now be compiled,and it's the problem to judge.I
    use the Process class in C#,and my thread is as follows:start a process
    using this class with parameters such as input file,output file,etc,and
    when the programme is running,i get its running information such as
    running time,used memory,etc.I code as follows:
    Process p = new Process();
    p.StartInfo.FileName = "cmd.exe";
    //p.StartInfo.Arguments = "/C &&exit";

    p.StartInfo.Arguments = "/C "+workPath + _pid.ToString() +
    ".exe <" + probPath + _pid.ToString() + ".in >" + workPath +
    _pid.ToString() + ".out &&exit";
    p.StartInfo.CreateNoWindow = true;
    p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
    p.Start();

    //while (!p.WaitForExit(_timelimit))
    while(!p.HasExited)
    {
    p.Refresh();
    memory = (int)(p.WorkingSet64 >> 10);
    runtime = p.UserProcessorTime.Milliseconds;
    Thread.Sleep(15);
    }
    hopefully to get info of programme,it really does!but the result is
    just strange.for instance,i write the following C file:
    #include <stdio.h>
    int main()
    {
    int i,j;
    for(i=0;i<1000000;i++)
    for(j=0;j<100;j++);
    return 0;
    }

    it comes out that this programme uses around 1800KB memory(this may be
    normal),but 0ms time----this is almost impossible! I test it alone,it
    run at least 400ms!
    there's another weird example:
    int main()
    {
    int i,j;
    scanf("%d%d",&i,&j);
    printf("%d",i+j);
    return 0;
    }

    this simple programme should use as much as 1600KB memory!!!

    Is there anyone who can tell me what's the problem with my
    programme?Or any better way to get used memory and running time of a
    programme? Appriciate your help!
     
    WangE, Nov 17, 2006
    #1
    1. Advertising

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. Kathy Burke
    Replies:
    2
    Views:
    711
    Kathy Burke
    Dec 3, 2003
  2. Replies:
    15
    Views:
    510
    Dave Thompson
    Aug 21, 2006
  3. pratap
    Replies:
    20
    Views:
    790
    Flash Gordon
    Mar 7, 2007
  4. Exe
    Replies:
    2
    Views:
    611
    Bug Hunter
    Jan 3, 2009
  5. Zam
    Replies:
    1
    Views:
    264
    Mark Schupp
    Mar 14, 2005
Loading...

Share This Page