gpt4 book ai didi

c# - 在 Mono 中使用 C# 的 Linux 进程 API

转载 作者:太空宇宙 更新时间:2023-11-04 09:36:35 25 4
gpt4 key购买 nike

我知道可以使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com