[Mono-list] To set process priority for Unix
~ * ~ Srijith Unni ~ * ~
srijith.unni at gmail.com
Mon May 28 00:38:34 EDT 2007
Hi Adrien,
Thanks for your help, I was able to reduce the priority of the
process by using P/Invoke and making calls to setpriority(), but ideally
shouldn`t the Process class encapsulate the working irrespective of the
underlying operating system. Like it should ideally have the intelligence
retrieve the operating system details and make the appropriate system calls.
Also is it possible for you to shed some light on the
Mono.Unix.Processclass and how it works.?
Thanks once again.
With Best Regards,
Srijith.
On 5/24/07, Adrien Dessemond <adrien.dessemond at softhome.net> wrote:
>
> Hi,
>
> > This is my first mail to this list, and I am a new Mono Developer. I
> > hope
> > to use this list to learn more about mono and C# on linux platforms.
> > I would like to know how it is possible to change the priority of a
> > process running on Unix based platform, say SuSe Linux, using C#
> compiled
> > on
> > Mono.
> > I have tried using this following Code snippet,
>
>
> >
> > Process Simple = new Process();
> >
> > Simple.StartInfo.FileName = "mono";
> > Simple.StartInfo.Arguments = "/home/ksrijith/Simple.exe";
> >
> > Simple.Start();
> >
> > Console.WriteLine("Simple Running with priority {0}",
> > Simple.PriorityClass);
> > Simple.PriorityClass = ProcessPriorityClass.BelowNormal ;
> >
> > But the priority of the process does not change and is always
> "Normal".
> > Is there any kind of privileges i need to set for this to work on Unix.
> or
> > is there any way i can do this using Mono.Unix namespace. ?
> >
> > Please excuse me, if this has already been discussed in the list. I
> am
> > a
> > newbie and didn`t know how to search the existing archives..!
>
> What you have to keep in mind is that Mono relies on your operating system
> API at the end : in the Linux world (as well as the other Unices/like
> ones), processes are created using exec?() and the so famous fork()
> system calls and it is not possible to tell them a new priority for the
> newly created process ("child processes are created like their father").
>
> But.. you can alter a process priority later and this operation is known
> as "renicing" : you can use either the renice command from the shell (see
> renice(1)) or use the setpriority() system call in your code (this implies
> a P/Invoke in your C# code). AFAK, "renicing" just gives the process
> scheduler a /hint/ about how it has to schedule your process /relatively/
> to the others and you are left at its mercy. Windows and Unices/likes
> handles that in a very different way, I do not have a precise knowledge
> about Windows and Unix scheduler internals so will I leave the explanation
> to someone else ;-)
>
> Under normal conditions, there are no reasons to alter a process nice
> value (may your application has to do heavy computations that could
> seriously slow down the system ?). If your program has to be run only on
> Linux/Unix, the best option for you is to launch it from a shell-script
> next put in the shell-script a renice call. Two reasons for that :
>
> 1. You follow the Unix "philosphy"
> 2. It will make you life easier (lowering a process nice value can be done
> under your standard user account but increasing it requires super-user
> privileges, so you could do "sudo" later).
>
> Hope that will help...
>
> Adrien.
>
> _______________________________________________
> Mono-list maillist - Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>
--
Thanks & Regards,
--
A.Srijith.K.Unni
Mail ID : srijith.unni at gmail.com
Home Page : http://srijith.unni.googlepages.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-list/attachments/20070528/721421bf/attachment.html
More information about the Mono-list
mailing list