summaryrefslogtreecommitdiffstats
path: root/vendor/rustix/examples/process.rs
blob: 49c6b8d9ec18657f7ff04a17276f2e230bb183b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//! A command which prints out information about the process it runs in.

use rustix::io;

#[cfg(all(feature = "process", feature = "param"))]
#[cfg(not(windows))]
fn main() -> io::Result<()> {
    use rustix::param::*;
    use rustix::process::*;

    println!("Pid: {}", getpid().as_raw_nonzero());
    println!("Parent Pid: {}", Pid::as_raw(getppid()));
    println!("Uid: {}", getuid().as_raw());
    println!("Gid: {}", getgid().as_raw());
    #[cfg(any(
        all(target_os = "android", target_pointer_width = "64"),
        target_os = "linux",
    ))]
    {
        let (a, b) = linux_hwcap();
        println!("Linux hwcap: {:#x}, {:#x}", a, b);
    }
    println!("Page size: {}", page_size());
    println!("Clock ticks/sec: {}", clock_ticks_per_second());
    println!("Uname: {:?}", uname());
    println!("Process group priority: {}", getpriority_pgrp(None)?);
    println!("Process priority: {}", getpriority_process(None)?);
    println!("User priority: {}", getpriority_user(Uid::ROOT)?);
    println!(
        "Current working directory: {}",
        getcwd(Vec::new())?.to_string_lossy()
    );
    println!("Cpu Limit: {:?}", getrlimit(Resource::Cpu));
    println!("Fsize Limit: {:?}", getrlimit(Resource::Fsize));
    println!("Data Limit: {:?}", getrlimit(Resource::Data));
    println!("Stack Limit: {:?}", getrlimit(Resource::Stack));
    println!("Core Limit: {:?}", getrlimit(Resource::Core));
    println!("Rss Limit: {:?}", getrlimit(Resource::Rss));
    println!("Nproc Limit: {:?}", getrlimit(Resource::Nproc));
    println!("Nofile Limit: {:?}", getrlimit(Resource::Nofile));
    println!("Memlock Limit: {:?}", getrlimit(Resource::Memlock));
    #[cfg(not(target_os = "openbsd"))]
    println!("As Limit: {:?}", getrlimit(Resource::As));
    #[cfg(not(any(
        target_os = "freebsd",
        target_os = "ios",
        target_os = "macos",
        target_os = "netbsd",
        target_os = "openbsd",
    )))]
    println!("Locks Limit: {:?}", getrlimit(Resource::Locks));
    #[cfg(not(any(
        target_os = "freebsd",
        target_os = "ios",
        target_os = "macos",
        target_os = "netbsd",
        target_os = "openbsd",
    )))]
    println!("Sigpending Limit: {:?}", getrlimit(Resource::Sigpending));
    #[cfg(not(any(
        target_os = "freebsd",
        target_os = "ios",
        target_os = "macos",
        target_os = "netbsd",
        target_os = "openbsd",
    )))]
    println!("Msgqueue Limit: {:?}", getrlimit(Resource::Msgqueue));
    #[cfg(not(any(
        target_os = "freebsd",
        target_os = "ios",
        target_os = "macos",
        target_os = "netbsd",
        target_os = "openbsd",
    )))]
    println!("Nice Limit: {:?}", getrlimit(Resource::Nice));
    #[cfg(not(any(
        target_os = "freebsd",
        target_os = "ios",
        target_os = "macos",
        target_os = "netbsd",
        target_os = "openbsd",
    )))]
    println!("Rtprio Limit: {:?}", getrlimit(Resource::Rtprio));
    #[cfg(not(any(
        target_os = "android",
        target_os = "emscripten",
        target_os = "freebsd",
        target_os = "ios",
        target_os = "macos",
        target_os = "netbsd",
        target_os = "openbsd",
    )))]
    println!("Rttime Limit: {:?}", getrlimit(Resource::Rttime));
    #[cfg(any(
        all(target_os = "android", target_pointer_width = "64"),
        target_os = "linux"
    ))]
    println!("Execfn: {:?}", linux_execfn());
    Ok(())
}

#[cfg(any(windows, not(all(feature = "process", feature = "param"))))]
fn main() -> io::Result<()> {
    unimplemented!()
}