472,143 Members | 1,155 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,143 software developers and data experts.

strange thing using Process class to call outside executable file

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!

Nov 17 '06 #1
1 1754
Hi Wang,

Check out Performance Counters. Specifically, the "Process" category.

"Performance Counters"
http://msdn.microsoft.com/library/de...cecounters.asp

--
Dave Sexton

"Wang E" <wa********@gmail.comwrote in message
news:11**********************@m7g2000cwm.googlegro ups.com...
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!

Nov 17 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Jane Austine | last post: by
6 posts views Thread by Edd Dawson | last post: by
6 posts views Thread by WSobczuk | last post: by
6 posts views Thread by Robin Riley | last post: by
3 posts views Thread by Vicky_r | last post: by
11 posts views Thread by Mike C# | last post: by
3 posts views Thread by =?Utf-8?B?UnVkeQ==?= | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.