pstree 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d8de7f08591e54e2af49ad0d5c779735a0f1c7979137b1b4dc21420b43e3d952
4
- data.tar.gz: b3ea7e35f07949e14f6cb8ca9909b1f0cfed59ca041d5e82a5362a6436ea486f
3
+ metadata.gz: 47afd4e4734bfc1207cc7ac432880efd4a15689bf2cf9b25f50ab3583a748e98
4
+ data.tar.gz: 4825f7854d8e02ac38451804209ddc6c61378c5c35d3139700fa8b1bbd30d49c
5
5
  SHA512:
6
- metadata.gz: 0add077fd833f7437d3453ec0b56fe66d17adf366d7db98b6b4b6fb52110c3688bc5dd4c7ba20a100ae2a88b139f95c013e1f2e07f9ab43e885632cebf87d462
7
- data.tar.gz: 1e2f5243524f03346f3eb1d450c21c59b79573146afb1c787924e1bad5e33d659cdc6aa3b92cd796cc0a56de7aa912fed5d3aac82193aa051b94e48155818b6f
6
+ metadata.gz: 65425a386c1966d95f70137c3eca9d59d9d2f48b944e23bcea44072de7639b12d137700d708bd13c24be0c111b9b3305c4d09ac0243d2e308b02e69f97e69760
7
+ data.tar.gz: 21b6b6df89ed649cea68509e8c2e96d87fdcf81f4d5d5f6ae9cb28d4a45165a1acab3ce09c6a79f916a8e08d9ded5c3582742afb2107d2b6b1d51cb18cb7b3e0
data/CHANGES.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changes
2
2
 
3
+ ## 2025-08-19 v0.5.0
4
+
5
+ - **Documentation**: Comprehensive YARD documentation added to all classes and
6
+ methods, with improved README containing installation instructions and usage
7
+ examples
8
+ - **Licensing**: Full GPL-2.0 license file included in gem package
9
+ - **Packaging**: Refined gemspec and Rakefile configurations to exclude
10
+ unnecessary files
11
+
3
12
  ## 2024-09-24 v0.4.0
4
13
 
5
14
  + Supports display of forrest now if more than one `PID` was given as arguments.
@@ -12,39 +21,39 @@
12
21
  ## 2024-03-15 v0.3.1
13
22
 
14
23
  * **Changes for version **1.0**:
15
- + Use `github` as homepage.
16
- + Create `codeql-analysis.yml`.
17
- + Update `gemspec`.
18
- + Configure `asdf`.
24
+ + Use `github` as homepage.
25
+ + Create `codeql-analysis.yml`.
26
+ + Update `gemspec`.
27
+ + Configure `asdf`.
19
28
 
20
29
  ## 2019-04-15 v0.3.0
21
30
 
22
31
  * Convert `rdoc README` to markdown
23
32
  * Only recurse into this one subtree correctly
24
33
  * Merge changes from `github.com:flori/pstree`
25
- + Support UTF-8 output and use it by default (default encoding changed to **UTF-8**)
26
- + Update code to use new default encoding (**UTF-8**)
34
+ + Support UTF-8 output and use it by default (default encoding changed to **UTF-8**)
35
+ + Update code to use new default encoding (**UTF-8**)
27
36
 
28
37
  ## 2017-11-07 v0.2.0
29
38
 
30
39
  * **Support UTF-8 output and use it by default**
31
- + Added support for UTF-8 output
32
- + Changed default output encoding to UTF-8
40
+ + Added support for UTF-8 output
41
+ + Changed default output encoding to UTF-8
33
42
  * **Cleanup code**
34
- + Improved code organization and structure
43
+ + Improved code organization and structure
35
44
  * **stop ruby 1.9 from whining**
36
- + Updated code to be compatible with Ruby 1.9
45
+ + Updated code to be compatible with Ruby 1.9
37
46
 
38
47
  ## 2014-02-06 v0.1.0
39
48
 
40
49
  * **Bumped gem_hadar dependency**:
41
- + Updated `gem_hadar` dependency to use the latest version
50
+ + Updated `gem_hadar` dependency to use the latest version
42
51
  * **Dependency on new version of gem_hadar**:
43
- + Updated `gem_hadar` dependency to use a new version (**1.0.0**)
52
+ + Updated `gem_hadar` dependency to use a new version (**1.0.0**)
44
53
  * **Cleanup code**:
45
- + Improved code organization and readability
54
+ + Improved code organization and readability
46
55
  * **Fix stupid ruby warning**:
47
- + Resolved a Ruby warning issue
56
+ + Resolved a Ruby warning issue
48
57
 
49
58
  ## 2013-05-15 v0.0.0
50
59
 
data/LICENSE ADDED
@@ -0,0 +1,338 @@
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5
+ <https://fsf.org/>
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your
12
+ freedom to share and change it. By contrast, the GNU General Public
13
+ License is intended to guarantee your freedom to share and change free
14
+ software--to make sure the software is free for all its users. This
15
+ General Public License applies to most of the Free Software
16
+ Foundation's software and to any other program whose authors commit to
17
+ using it. (Some other Free Software Foundation software is covered by
18
+ the GNU Lesser General Public License instead.) You can apply it to
19
+ your programs, too.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ this service if you wish), that you receive source code or can get it
25
+ if you want it, that you can change the software or use pieces of it
26
+ in new free programs; and that you know you can do these things.
27
+
28
+ To protect your rights, we need to make restrictions that forbid
29
+ anyone to deny you these rights or to ask you to surrender the rights.
30
+ These restrictions translate to certain responsibilities for you if you
31
+ distribute copies of the software, or if you modify it.
32
+
33
+ For example, if you distribute copies of such a program, whether
34
+ gratis or for a fee, you must give the recipients all the rights that
35
+ you have. You must make sure that they, too, receive or can get the
36
+ source code. And you must show them these terms so they know their
37
+ rights.
38
+
39
+ We protect your rights with two steps: (1) copyright the software, and
40
+ (2) offer you this license which gives you legal permission to copy,
41
+ distribute and/or modify the software.
42
+
43
+ Also, for each author's protection and ours, we want to make certain
44
+ that everyone understands that there is no warranty for this free
45
+ software. If the software is modified by someone else and passed on, we
46
+ want its recipients to know that what they have is not the original, so
47
+ that any problems introduced by others will not reflect on the original
48
+ authors' reputations.
49
+
50
+ Finally, any free program is threatened constantly by software
51
+ patents. We wish to avoid the danger that redistributors of a free
52
+ program will individually obtain patent licenses, in effect making the
53
+ program proprietary. To prevent this, we have made it clear that any
54
+ patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+ 0. This License applies to any program or other work which contains
63
+ a notice placed by the copyright holder saying it may be distributed
64
+ under the terms of this General Public License. The "Program", below,
65
+ refers to any such program or work, and a "work based on the Program"
66
+ means either the Program or any derivative work under copyright law:
67
+ that is to say, a work containing the Program or a portion of it,
68
+ either verbatim or with modifications and/or translated into another
69
+ language. (Hereinafter, translation is included without limitation in
70
+ the term "modification".) Each licensee is addressed as "you".
71
+
72
+ Activities other than copying, distribution and modification are not
73
+ covered by this License; they are outside its scope. The act of
74
+ running the Program is not restricted, and the output from the Program
75
+ is covered only if its contents constitute a work based on the
76
+ Program (independent of having been made by running the Program).
77
+ Whether that is true depends on what the Program does.
78
+
79
+ 1. You may copy and distribute verbatim copies of the Program's
80
+ source code as you receive it, in any medium, provided that you
81
+ conspicuously and appropriately publish on each copy an appropriate
82
+ copyright notice and disclaimer of warranty; keep intact all the
83
+ notices that refer to this License and to the absence of any warranty;
84
+ and give any other recipients of the Program a copy of this License
85
+ along with the Program.
86
+
87
+ You may charge a fee for the physical act of transferring a copy, and
88
+ you may at your option offer warranty protection in exchange for a fee.
89
+
90
+ 2. You may modify your copy or copies of the Program or any portion
91
+ of it, thus forming a work based on the Program, and copy and
92
+ distribute such modifications or work under the terms of Section 1
93
+ above, provided that you also meet all of these conditions:
94
+
95
+ a) You must cause the modified files to carry prominent notices
96
+ stating that you changed the files and the date of any change.
97
+
98
+ b) You must cause any work that you distribute or publish, that in
99
+ whole or in part contains or is derived from the Program or any
100
+ part thereof, to be licensed as a whole at no charge to all third
101
+ parties under the terms of this License.
102
+
103
+ c) If the modified program normally reads commands interactively
104
+ when run, you must cause it, when started running for such
105
+ interactive use in the most ordinary way, to print or display an
106
+ announcement including an appropriate copyright notice and a
107
+ notice that there is no warranty (or else, saying that you provide
108
+ a warranty) and that users may redistribute the program under
109
+ these conditions, and telling the user how to view a copy of this
110
+ License. (Exception: if the Program itself is interactive but
111
+ does not normally print such an announcement, your work based on
112
+ the Program is not required to print an announcement.)
113
+
114
+ These requirements apply to the modified work as a whole. If
115
+ identifiable sections of that work are not derived from the Program,
116
+ and can be reasonably considered independent and separate works in
117
+ themselves, then this License, and its terms, do not apply to those
118
+ sections when you distribute them as separate works. But when you
119
+ distribute the same sections as part of a whole which is a work based
120
+ on the Program, the distribution of the whole must be on the terms of
121
+ this License, whose permissions for other licensees extend to the
122
+ entire whole, and thus to each and every part regardless of who wrote it.
123
+
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
195
+ this License.
196
+
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
200
+ otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
+ be similar in spirit to the present version, but may differ in detail to
240
+ address new problems or concerns.
241
+
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
279
+
280
+ END OF TERMS AND CONDITIONS
281
+
282
+ How to Apply These Terms to Your New Programs
283
+
284
+ If you develop a new program, and you want it to be of the greatest
285
+ possible use to the public, the best way to achieve this is to make it
286
+ free software which everyone can redistribute and change under these terms.
287
+
288
+ To do so, attach the following notices to the program. It is safest
289
+ to attach them to the start of each source file to most effectively
290
+ convey the exclusion of warranty; and each file should have at least
291
+ the "copyright" line and a pointer to where the full notice is found.
292
+
293
+ <one line to give the program's name and a brief idea of what it does.>
294
+ Copyright (C) <year> <name of author>
295
+
296
+ This program is free software; you can redistribute it and/or modify
297
+ it under the terms of the GNU General Public License as published by
298
+ the Free Software Foundation; either version 2 of the License, or
299
+ (at your option) any later version.
300
+
301
+ This program is distributed in the hope that it will be useful,
302
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
303
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
+ GNU General Public License for more details.
305
+
306
+ You should have received a copy of the GNU General Public License along
307
+ with this program; if not, see <https://www.gnu.org/licenses/>.
308
+
309
+ Also add information on how to contact you by electronic and paper mail.
310
+
311
+ If the program is interactive, make it output a short notice like this
312
+ when it starts in an interactive mode:
313
+
314
+ Gnomovision version 69, Copyright (C) year name of author
315
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
316
+ This is free software, and you are welcome to redistribute it
317
+ under certain conditions; type `show c' for details.
318
+
319
+ The hypothetical commands `show w' and `show c' should show the appropriate
320
+ parts of the General Public License. Of course, the commands you use may
321
+ be called something other than `show w' and `show c'; they could even be
322
+ mouse-clicks or menu items--whatever suits your program.
323
+
324
+ You should also get your employer (if you work as a programmer) or your
325
+ school, if any, to sign a "copyright disclaimer" for the program, if
326
+ necessary. Here is a sample; alter the names:
327
+
328
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
329
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
330
+
331
+ <signature of Moe Ghoul>, 1 April 1989
332
+ Moe Ghoul, President of Vice
333
+
334
+ This General Public License does not permit incorporating your program into
335
+ proprietary programs. If your program is a subroutine library, you may
336
+ consider it more useful to permit linking proprietary applications with the
337
+ library. If this is what you want to do, use the GNU Lesser General
338
+ Public License instead of this License.
data/README.md CHANGED
@@ -2,14 +2,40 @@
2
2
 
3
3
  ## Description
4
4
 
5
- This library can be used to create and display a process status tree as a Ruby
6
- datastructure.
5
+ This library provides a Ruby implementation of the `pstree` utility, enabling
6
+ developers to visualize process hierarchies as tree structures. It parses
7
+ system process information and presents it in an easily readable format with
8
+ proper indentation and Unicode/ASCII tree characters.
9
+
10
+ The library can be used both programmatically as a data structure and through
11
+ its command-line interface for quick process tree visualization.
7
12
 
8
13
  ## Installation
9
14
 
10
- Install the gem by typing
15
+ ### RubyGems
16
+
17
+ Install the latest version from RubyGems.org:
18
+
19
+ ```bash
20
+ gem install pstree
21
+ ```
22
+
23
+ ### Bundler
24
+
25
+ Add to your Gemfile:
26
+ ```ruby
27
+ gem 'pstree'
28
+ ```
29
+
30
+ Then run:
31
+ ```bash
32
+ bundle install
33
+ ```
11
34
 
12
- # gem install pstree
35
+ ## Requirements
36
+ - Ruby 2.0 or higher
37
+ - UNIX-like operating system (Linux, macOS, BSD)
38
+ - `/bin/ps` utility available in PATH
13
39
 
14
40
  ## Usage
15
41
 
@@ -22,18 +48,38 @@ $ ruby-pstree $$
22
48
  └─ 37129 /bin/ps axww -o ppid,pid,user,command (root)
23
49
  ```
24
50
 
51
+ ### Programmatic Usage
52
+
53
+ Access process information programmatically:
54
+
55
+ ```ruby
56
+ require 'pstree'
57
+
58
+ # Create a process tree for PID 1 (init)
59
+ tree = PSTree.new(1)
60
+
61
+ # Iterate over processes in the tree
62
+ tree.each do |process|
63
+ puts "#{process.pid}: #{process.cmd}"
64
+ end
65
+
66
+ # Or get the tree as a string
67
+ puts tree.to_s
68
+
69
+ # Navigate the tree to find the pids of your favourite processes
70
+ pid_of_shell_parent_of_irb = tree.find { it.cmd =~ /irb/ }&.ppid
71
+ ```
72
+
25
73
  ## Download
26
74
 
27
75
  The homepage of this library is located at
28
76
 
29
- * http://flori.github.com/pstree
77
+ * https://github.com/flori/pstree
30
78
 
31
79
  ## Author
32
80
 
33
- Florian Frank <flori@ping.de>
81
+ [Florian Frank](mailto:flori@ping.de)
34
82
 
35
83
  ## License
36
84
 
37
- This is free software; you can redistribute it and/or modify it under the
38
- terms of the GNU General Public License Version 2 as published by the Free
39
- Software Foundation: www.gnu.org/copyleft/gpl.html
85
+ [GPLv2 License](./LICENSE)
data/Rakefile CHANGED
@@ -13,7 +13,10 @@ GemHadar do
13
13
  description 'This library uses the output of the ps command to creaste process tree data structure for the current host.'
14
14
  licenses << 'GPL-2'
15
15
  test_dir 'tests'
16
- ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', '.rvmrc', 'coverage'
16
+ ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', '.rvmrc', 'coverage',
17
+ '.yardoc', 'doc'
18
+ package_ignore '.all_images', '.utilsrc', '.rspec', '.tool-versions',
19
+ '.gitignore'
17
20
  readme 'README.md'
18
21
  executables << 'ruby-pstree'
19
22
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.5.0
@@ -1,6 +1,6 @@
1
1
  class PSTree
2
2
  # PSTree version
3
- VERSION = '0.4.0'
3
+ VERSION = '0.5.0'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
data/lib/pstree.rb CHANGED
@@ -1,13 +1,68 @@
1
1
  require 'pstree/version'
2
2
 
3
+ # PSTree is a process status tree implementation that creates and displays
4
+ # hierarchical process information.
5
+ #
6
+ # This class provides functionality to build and visualize process trees
7
+ # starting from a specified root process ID. It encapsulates process data
8
+ # including parent process ID, process ID, user, and command line, and formats
9
+ # this information into a readable tree structure with proper indentation and
10
+ # branch characters.
11
+ #
12
+ # @example Creating and displaying a process tree
13
+ # tree = PSTree.new($$)
14
+ # puts tree.to_s
15
+ #
16
+ # @example Iterating over processes in the tree
17
+ # tree = PSTree.new($$)
18
+ # tree.each do |process|
19
+ # puts process.pid
20
+ # end
3
21
  class PSTree
22
+ # Process structure for storing and formatting process information.
23
+ #
24
+ # This class encapsulates the essential details of a process including its
25
+ # parent process ID, process ID, owning user, and command line.
26
+ #
27
+ # @example Creating a new process structure
28
+ # proc = PSTree::ProcStruct.new(1234, 5678, 'flori', '/usr/bin/ruby script.rb')
4
29
  class ProcStruct
30
+ # Initializes a new process structure with the given process information.
31
+ #
32
+ # @param ppid [ String, Integer ] the parent process ID
33
+ # @param pid [ String, Integer ] the process ID
34
+ # @param user [ String ] the user who owns the process
35
+ # @param cmd [ String ] the command line of the process
5
36
  def initialize(ppid, pid, user, cmd)
6
37
  @ppid, @pid, @user, @cmd = ppid.to_i, pid.to_i, user, cmd
7
38
  end
8
39
 
9
- attr_reader :ppid, :pid, :user, :cmd
40
+ # The ppid reader method returns the parent process ID of this process
41
+ # structure.
42
+ #
43
+ # @attr_reader [ Integer ] the parent process identifier
44
+ attr_reader :ppid
10
45
 
46
+ # The pid reader method returns the process ID of this process structure.
47
+ #
48
+ # @attr_reader [ Integer ] the process identifier
49
+ attr_reader :pid
50
+
51
+ # The user reader method returns the username who owns this process
52
+ #
53
+ # @attr_reader [ String ] the user identifier who owns the process
54
+ attr_reader :user
55
+
56
+ # The cmd reader method returns the command line of this process structure.
57
+ #
58
+ # @attr_reader [ String ] the command line associated with the process
59
+ attr_reader :cmd
60
+
61
+ # The to_s method formats the process information into a string representation
62
+ # that displays the process ID, command, and user in a standardized format.
63
+ #
64
+ # @return [ String ] a formatted string containing the process ID, command,
65
+ # and user separated by spaces and parentheses
11
66
  def to_s
12
67
  "%05u %s (%s)" % [ pid, cmd, user ]
13
68
  end
@@ -15,11 +70,26 @@ class PSTree
15
70
 
16
71
  include Enumerable
17
72
 
73
+ # Initializes a new PSTree instance with the specified root process ID and character set.
74
+ #
75
+ # @param root_pid [ String, Integer, nil ] the process ID of the root process
76
+ # to start the tree from
77
+ # @param charset [ String ] the character encoding to use for display
78
+ # formatting
18
79
  def initialize(root_pid = nil, charset: 'UTF-8')
19
80
  @charset = charset.to_s.upcase
20
81
  @root_pid = root_pid.to_i
21
82
  end
22
83
 
84
+ # Returns the appropriate tree drawing character sequence for a process with
85
+ # zero children, based on the current charset setting.
86
+ #
87
+ # @param last [ TrueClass, FalseClass ] whether this is the last child in a
88
+ # sequence
89
+ #
90
+ # @return [ String ] the character sequence to use for drawing the tree branch
91
+ # line, either UTF-8 or ASCII characters depending on charset
92
+ # configuration
23
93
  def children_zero(last)
24
94
  if @charset == 'UTF-8'
25
95
  last ? '└─ ' : ' '
@@ -28,6 +98,15 @@ class PSTree
28
98
  end
29
99
  end
30
100
 
101
+ # Returns the appropriate tree drawing character sequence for a process with
102
+ # children, based on the current charset setting and whether the process is
103
+ # the last child in a sequence.
104
+ #
105
+ # @param last [ TrueClass, FalseClass ] whether this is the last child in a sequence
106
+ #
107
+ # @return [ String ] the character sequence to use for drawing the tree
108
+ # branch line, either UTF-8 or ASCII characters depending
109
+ # on charset configuration
31
110
  def children_not_zero(last)
32
111
  if @charset == 'UTF-8'
33
112
  last ? '├─ ' : '│ '
@@ -36,6 +115,14 @@ class PSTree
36
115
  end
37
116
  end
38
117
 
118
+ # The to_s method generates a string representation of the process tree
119
+ # starting from the root process ID. It builds the tree structure and formats
120
+ # each process entry with appropriate tree-drawing characters based on the
121
+ # process hierarchy and charset configuration. The resulting string includes
122
+ # process IDs, commands, and users in a hierarchical display format.
123
+ #
124
+ # @return [ String ] a formatted string representation of the process tree
125
+ # with proper indentation and tree-drawing characters
39
126
  def to_s
40
127
  build
41
128
  result = ''
@@ -52,6 +139,12 @@ class PSTree
52
139
  result
53
140
  end
54
141
 
142
+ # The each method iterates over all processes in the process tree by
143
+ # executing the given block for each process.
144
+ #
145
+ # @yield [ ps ]
146
+ #
147
+ # @return [ PSTree ] returns itself to allow for method chaining
55
148
  def each(&block)
56
149
  build
57
150
  recurse @root_pid, &block
@@ -60,6 +153,14 @@ class PSTree
60
153
 
61
154
  private
62
155
 
156
+ # The build method constructs the internal process tree data structure by
157
+ # parsing output from the ps command.
158
+ #
159
+ # It initializes the necessary instance variables and populates them with
160
+ # process information obtained from executing the /bin/ps command with
161
+ # specific output format options. The method processes each line of the ps
162
+ # output to create ProcStruct objects and organizes them into a hierarchical
163
+ # tree structure based on parent process IDs.
63
164
  def build
64
165
  @child_count = [ 0 ]
65
166
  @process = {}
@@ -74,6 +175,20 @@ class PSTree
74
175
  end
75
176
  end
76
177
 
178
+ # The recurse method performs a recursive traversal of the process tree
179
+ # starting from a given process ID.
180
+ #
181
+ # It processes each node in the tree by executing the provided callback for
182
+ # the current process, then recursively processes all child processes. The
183
+ # method handles tree drawing character generation based on the hierarchy
184
+ # level and whether a process has children.
185
+ #
186
+ # @param pid [ Integer ] the process ID to start recursion from
187
+ # @param shift_callback [ Proc, nil ] optional callback to generate tree drawing characters
188
+ # @param level [ Integer ] current depth level in the tree hierarchy
189
+ # @param in_root [ TrueClass, FalseClass ] flag indicating if current node is the root
190
+ #
191
+ # @yield [ ps ]
77
192
  def recurse(pid, shift_callback = nil, level = 0, in_root = false, &node_callback)
78
193
  in_root = in_root || @root_pid == 0 || @root_pid == pid
79
194
  @child_count[level] = @pstree[pid].size
data/pstree.gemspec CHANGED
@@ -1,26 +1,26 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: pstree 0.4.0 ruby lib
2
+ # stub: pstree 0.5.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "pstree".freeze
6
- s.version = "0.4.0".freeze
6
+ s.version = "0.5.0".freeze
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
10
10
  s.authors = ["Florian Frank".freeze]
11
- s.date = "2024-09-24"
11
+ s.date = "1980-01-02"
12
12
  s.description = "This library uses the output of the ps command to creaste process tree data structure for the current host.".freeze
13
13
  s.email = "flori@ping.de".freeze
14
14
  s.executables = ["ruby-pstree".freeze]
15
15
  s.extra_rdoc_files = ["README.md".freeze, "lib/pstree.rb".freeze, "lib/pstree/version.rb".freeze]
16
- s.files = [".github/workflows/codeql-analysis.yml".freeze, ".gitignore".freeze, "CHANGES.md".freeze, "Gemfile".freeze, "README.md".freeze, "Rakefile".freeze, "VERSION".freeze, "bin/ruby-pstree".freeze, "lib/pstree.rb".freeze, "lib/pstree/version.rb".freeze, "pstree.gemspec".freeze]
16
+ s.files = [".github/workflows/codeql-analysis.yml".freeze, "CHANGES.md".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "VERSION".freeze, "bin/ruby-pstree".freeze, "lib/pstree.rb".freeze, "lib/pstree/version.rb".freeze, "pstree.gemspec".freeze]
17
17
  s.homepage = "https://github.com/flori/pstree".freeze
18
18
  s.licenses = ["GPL-2".freeze]
19
19
  s.rdoc_options = ["--title".freeze, "Pstree - Ruby library that builds a process tree of this host".freeze, "--main".freeze, "README.md".freeze]
20
- s.rubygems_version = "3.5.18".freeze
20
+ s.rubygems_version = "3.6.9".freeze
21
21
  s.summary = "Ruby library that builds a process tree of this host".freeze
22
22
 
23
23
  s.specification_version = 4
24
24
 
25
- s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 1.17.1".freeze])
25
+ s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 2.1".freeze])
26
26
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pstree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-09-24 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: gem_hadar
@@ -16,14 +15,14 @@ dependencies:
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: 1.17.1
18
+ version: '2.1'
20
19
  type: :development
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - "~>"
25
24
  - !ruby/object:Gem::Version
26
- version: 1.17.1
25
+ version: '2.1'
27
26
  description: This library uses the output of the ps command to creaste process tree
28
27
  data structure for the current host.
29
28
  email: flori@ping.de
@@ -36,9 +35,9 @@ extra_rdoc_files:
36
35
  - lib/pstree/version.rb
37
36
  files:
38
37
  - ".github/workflows/codeql-analysis.yml"
39
- - ".gitignore"
40
38
  - CHANGES.md
41
39
  - Gemfile
40
+ - LICENSE
42
41
  - README.md
43
42
  - Rakefile
44
43
  - VERSION
@@ -50,7 +49,6 @@ homepage: https://github.com/flori/pstree
50
49
  licenses:
51
50
  - GPL-2
52
51
  metadata: {}
53
- post_install_message:
54
52
  rdoc_options:
55
53
  - "--title"
56
54
  - Pstree - Ruby library that builds a process tree of this host
@@ -69,8 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
67
  - !ruby/object:Gem::Version
70
68
  version: '0'
71
69
  requirements: []
72
- rubygems_version: 3.5.18
73
- signing_key:
70
+ rubygems_version: 3.6.9
74
71
  specification_version: 4
75
72
  summary: Ruby library that builds a process tree of this host
76
73
  test_files: []
data/.gitignore DELETED
@@ -1,5 +0,0 @@
1
- .*.sw[pon]
2
- .rvmrc
3
- Gemfile.lock
4
- coverage
5
- pkg