我知道可以使用 Mono 在 Linux 中编写 C# .NET 应用程序。但是,我想知道 Linux 的进程接口(interface)。我可以使用 C# 和 Mono 并在 Linux 环境中运行的 getpid()
、getppid()
和 fork()
等服务吗?
最佳答案
对于 getpid()
和 getppid()
你可以使用 Syscall这样:
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);
}
}
}
你需要 Mono.Posix.dll
对于 fork()
你可以使用 Process .请参阅此处的示例:creating child process with C#
关于 Process Class C# 的文档.
关于c# - 在 Mono 中使用 C# 的 Linux 进程 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25950517/