I know it is possible to code C# .NET apps in Linux using Mono. However, I am wondering about the process interfaces of Linux. Could I use services like getpid(), getppid() and fork() using C# and Mono and running on a Linux environment?
-
Do you really need to spawn new system processes, or is it enough to have managed threads inside the Mono VM?knittl– knittl2014-09-21 17:56:21 +00:00Commented Sep 21, 2014 at 17:56
Add a comment
|
1 Answer
For getpid() and getppid() you could use Syscall in this way:
using System;
using Mono.Unix.Native;
namespace StackOverflow
{
class MainClass
{
public static void Main(string[] args)
{
int pid = Syscall.getpid();
int ppid = Syscall.getppid();
Console.WriteLine ("PID: {0}", pid);
Console.WriteLine ("PPID: {0}", ppid);
}
}
}
You need Mono.Posix.dll
For fork() you can use Process. See example here: creating child process with C#
Documentation about Process Class C#.