File tree Expand file tree Collapse file tree 3 files changed +83
-0
lines changed Expand file tree Collapse file tree 3 files changed +83
-0
lines changed Original file line number Diff line number Diff line change
1
+ /* MIT License
2
+ #
3
+ # Copyright (c) 2020 Ferhat Geçdoğan All Rights Reserved.
4
+ # Distributed under the terms of the MIT License.
5
+ #
6
+ # */
7
+
8
+ #ifndef PROCESS_PLUS_PLUS_HPP
9
+ #define PROCESS_PLUS_PLUS_HPP
10
+
11
+ #include < iostream>
12
+ #include < sys/stat.h>
13
+ #include < dirent.h>
14
+ #include < bits/stdc++.h>
15
+ #include < list>
16
+
17
+
18
+ namespace procplusplus {
19
+ std::ostream& operator <<(std::ostream& ostr, const std::list<int >& list) {
20
+ for (auto &i : list)
21
+ ostr << i << " \n " ;
22
+
23
+ return ostr;
24
+ }
25
+
26
+ /* std::list<int>&*/ void GetPID () {
27
+ struct dirent *entryname;
28
+ struct stat filestat;
29
+ std::list<int > pid;
30
+ int line =0 ;
31
+ DIR *directory;
32
+ directory = opendir (" /proc" );
33
+
34
+ if (directory == NULL ) {
35
+ std::cout << " Directory not found.\n " ;
36
+ }
37
+
38
+ while ((entryname = readdir (directory))) {
39
+ stat (entryname->d_name , &filestat);
40
+ if (entryname->d_type == DT_DIR) {// DT_DIR -> directory
41
+ if (strstr (entryname->d_name , " ." )) {
42
+ // Null
43
+ } else if (strstr (entryname->d_name , " .." )){
44
+ // Null
45
+ } else {
46
+ int a = atoi (entryname->d_name );
47
+ if (a != 0 )
48
+ pid.push_back (a);
49
+ }
50
+ }
51
+ }
52
+
53
+ pid.sort (std::less<int >());
54
+
55
+ std::cout << pid;
56
+
57
+ closedir (directory);
58
+ }
59
+ }
60
+
61
+ #endif /* PROCESS_PLUS_PLUS_HPP */
Original file line number Diff line number Diff line change
1
+ #! /bin/sh
2
+ # Shebang line
3
+
4
+ c++ -I. test.cpp -o test && ./test
Original file line number Diff line number Diff line change
1
+ /* MIT License
2
+ #
3
+ # Copyright (c) 2020 Ferhat Geçdoğan All Rights Reserved.
4
+ # Distributed under the terms of the MIT License.
5
+ #
6
+ # */
7
+
8
+ #include < iostream>
9
+ #include < ProcessPlusPlus.hpp>
10
+
11
+ /*
12
+ List all PIDs.
13
+ */
14
+ int main (int argc, char ** argv) {
15
+ std::cout << " PID:\n " ;
16
+ procplusplus::GetPID ();
17
+ return 0 ;
18
+ }
You can’t perform that action at this time.
0 commit comments