Kaynağa Gözat

Began hw4/task1. Created functions.

Joshua Rutschmann 8 yıl önce
ebeveyn
işleme
84e50b85b0

+ 7
- 0
hw4/task1/Cargo.toml Dosyayı Görüntüle

@@ -0,0 +1,7 @@
1
+[package]
2
+name = "task1"
3
+version = "0.1.0"
4
+authors = ["Joshua Rutschmann <joshua.rutschmann@gmx.de>"]
5
+
6
+[dependencies]
7
+procinfo = "^0.4.2"

+ 9
- 0
hw4/task1/src/main.rs Dosyayı Görüntüle

@@ -0,0 +1,9 @@
1
+extern crate procinfo;
2
+
3
+mod readproc;
4
+mod pstree;
5
+
6
+fn main() {
7
+    println!("Hello, world!");
8
+    println!("{:?}", readproc::self_pids());
9
+}

+ 0
- 0
hw4/task1/src/pstree.rs Dosyayı Görüntüle


+ 31
- 0
hw4/task1/src/readproc.rs Dosyayı Görüntüle

@@ -0,0 +1,31 @@
1
+use procinfo::pid::Stat;
2
+use procinfo::pid;
3
+
4
+pub fn self_pids() -> Result<(i32, i32), &'static str>{
5
+    match pid::stat_self() {
6
+        Ok(stat) => { Ok((stat.pid, stat.ppid)) }
7
+        Err(_) => { Err("Fehler") }
8
+    }
9
+}
10
+
11
+pub fn get_pid_command(pid: i32) -> Result<String, &'static str> {
12
+    match pid::stat(pid) {
13
+        Ok(stat) => { Ok(stat.command) }
14
+        Err(_) => { Err("Fehler") }
15
+    }
16
+}
17
+
18
+pub fn get_last_created_command() -> Result<String, &'static str> {
19
+    match pid::stat_self() {
20
+        Ok(stat) => { Ok(stat.command) }
21
+        Err(_) => { Err("Fehler") }
22
+    }
23
+
24
+}
25
+
26
+pub fn get_thread_count(pid: i32) -> Result<u32, &'static str> {
27
+    match pid::stat(pid) {
28
+        Ok(stat) => { Ok(stat.num_threads as u32) }
29
+        Err(_) => { Err("Fehler") }
30
+    }
31
+}

Loading…
İptal
Kaydet