Created
May 24, 2023 00:44
-
-
Save brianmed/8a36b67a6070607227e9727f92e1480f to your computer and use it in GitHub Desktop.
C# macOS getrlimit example via DllImport
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>net6.0</TargetFramework> | |
<ImplicitUsings>enable</ImplicitUsings> | |
<Nullable>enable</Nullable> | |
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | |
</PropertyGroup> | |
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Runtime.InteropServices; | |
namespace getrlimit; | |
class Program | |
{ | |
[DllImport("libc", CallingConvention = CallingConvention.Cdecl)] | |
public static extern int getrlimit(int resource, IntPtr rlp); | |
[StructLayout(LayoutKind.Sequential)] | |
public struct rlimit | |
{ | |
public Int64 rlim_cur; | |
public Int64 rlim_max; | |
} | |
static void Main(string[] args) | |
{ | |
int RLIMIT_STACK = 3; | |
rlimit joy = new(); | |
unsafe | |
{ | |
void *rlimitPtr = &joy; | |
getrlimit(RLIMIT_STACK, new(rlimitPtr)); | |
} | |
Console.WriteLine(joy.rlim_cur); | |
Console.WriteLine(joy.rlim_max); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment