1//! A command which prints out information about the process it runs in.
2
3use rustix::io;
4
5#[cfg(all(feature = "process", feature = "param"))]
6#[cfg(not(windows))]
7fn main() -> io::Result<()> {
8    use rustix::param::*;
9    use rustix::process::*;
10
11    println!("Pid: {}", getpid().as_raw_nonzero());
12    println!("Parent Pid: {}", Pid::as_raw(getppid()));
13    println!("Group Pid: {}", getpgrp().as_raw_nonzero());
14    if let Some(ppid) = getppid() {
15        println!(
16            "Parent Group Pid: {}",
17            getpgid(Some(ppid)).unwrap().as_raw_nonzero()
18        );
19    }
20    println!("Uid: {}", getuid().as_raw());
21    println!("Gid: {}", getgid().as_raw());
22    #[cfg(any(
23        all(target_os = "android", target_pointer_width = "64"),
24        target_os = "linux",
25    ))]
26    {
27        let (a, b) = linux_hwcap();
28        println!("Linux hwcap: {:#x}, {:#x}", a, b);
29    }
30    println!("Page size: {}", page_size());
31    println!("Clock ticks/sec: {}", clock_ticks_per_second());
32    println!("Uname: {:?}", uname());
33    #[cfg(not(target_os = "fuchsia"))]
34    {
35        println!("Process group priority: {}", getpriority_pgrp(None)?);
36        println!("Process priority: {}", getpriority_process(None)?);
37        println!("User priority: {}", getpriority_user(Uid::ROOT)?);
38    }
39    println!(
40        "Current working directory: {}",
41        getcwd(Vec::new())?.to_string_lossy()
42    );
43    #[cfg(not(target_os = "fuchsia"))]
44    {
45        println!("Cpu Limit: {:?}", getrlimit(Resource::Cpu));
46        println!("Fsize Limit: {:?}", getrlimit(Resource::Fsize));
47        println!("Data Limit: {:?}", getrlimit(Resource::Data));
48        println!("Stack Limit: {:?}", getrlimit(Resource::Stack));
49        #[cfg(not(target_os = "haiku"))]
50        println!("Core Limit: {:?}", getrlimit(Resource::Core));
51        #[cfg(not(any(target_os = "haiku", target_os = "illumos", target_os = "solaris")))]
52        println!("Rss Limit: {:?}", getrlimit(Resource::Rss));
53        #[cfg(not(any(target_os = "haiku", target_os = "illumos", target_os = "solaris")))]
54        println!("Nproc Limit: {:?}", getrlimit(Resource::Nproc));
55        #[cfg(not(target_os = "solaris"))]
56        println!("Nofile Limit: {:?}", getrlimit(Resource::Nofile));
57        #[cfg(not(any(target_os = "haiku", target_os = "illumos", target_os = "solaris")))]
58        println!("Memlock Limit: {:?}", getrlimit(Resource::Memlock));
59        #[cfg(not(target_os = "openbsd"))]
60        println!("As Limit: {:?}", getrlimit(Resource::As));
61        #[cfg(not(any(
62            target_os = "dragonfly",
63            target_os = "freebsd",
64            target_os = "haiku",
65            target_os = "illumos",
66            target_os = "ios",
67            target_os = "macos",
68            target_os = "netbsd",
69            target_os = "openbsd",
70            target_os = "solaris",
71        )))]
72        println!("Locks Limit: {:?}", getrlimit(Resource::Locks));
73        #[cfg(not(any(
74            target_os = "dragonfly",
75            target_os = "freebsd",
76            target_os = "haiku",
77            target_os = "illumos",
78            target_os = "ios",
79            target_os = "macos",
80            target_os = "netbsd",
81            target_os = "openbsd",
82            target_os = "solaris",
83        )))]
84        println!("Sigpending Limit: {:?}", getrlimit(Resource::Sigpending));
85        #[cfg(not(any(
86            target_os = "dragonfly",
87            target_os = "freebsd",
88            target_os = "haiku",
89            target_os = "illumos",
90            target_os = "ios",
91            target_os = "macos",
92            target_os = "netbsd",
93            target_os = "openbsd",
94            target_os = "solaris",
95        )))]
96        println!("Msgqueue Limit: {:?}", getrlimit(Resource::Msgqueue));
97        #[cfg(not(any(
98            target_os = "dragonfly",
99            target_os = "freebsd",
100            target_os = "haiku",
101            target_os = "illumos",
102            target_os = "ios",
103            target_os = "macos",
104            target_os = "netbsd",
105            target_os = "openbsd",
106            target_os = "solaris",
107        )))]
108        println!("Nice Limit: {:?}", getrlimit(Resource::Nice));
109        #[cfg(not(any(
110            target_os = "dragonfly",
111            target_os = "freebsd",
112            target_os = "haiku",
113            target_os = "illumos",
114            target_os = "ios",
115            target_os = "macos",
116            target_os = "netbsd",
117            target_os = "openbsd",
118            target_os = "solaris",
119        )))]
120        println!("Rtprio Limit: {:?}", getrlimit(Resource::Rtprio));
121        #[cfg(not(any(
122            target_os = "android",
123            target_os = "dragonfly",
124            target_os = "emscripten",
125            target_os = "freebsd",
126            target_os = "haiku",
127            target_os = "illumos",
128            target_os = "ios",
129            target_os = "macos",
130            target_os = "netbsd",
131            target_os = "openbsd",
132            target_os = "solaris",
133        )))]
134        println!("Rttime Limit: {:?}", getrlimit(Resource::Rttime));
135    }
136    #[cfg(any(
137        all(target_os = "android", target_pointer_width = "64"),
138        target_os = "linux"
139    ))]
140    println!("Execfn: {:?}", linux_execfn());
141    Ok(())
142}
143
144#[cfg(any(windows, not(all(feature = "process", feature = "param"))))]
145fn main() -> io::Result<()> {
146    unimplemented!()
147}
148