0

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?

1
  • Do you really need to spawn new system processes, or is it enough to have managed threads inside the Mono VM? Commented Sep 21, 2014 at 17:56

1 Answer 1

2

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#.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.