Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

treat cygwin like linux #4

Closed
badboybeyer opened this issue Jul 3, 2018 · 6 comments
Closed

treat cygwin like linux #4

badboybeyer opened this issue Jul 3, 2018 · 6 comments

Comments

@badboybeyer
Copy link

Treat cygwin like linux, because its ps command is limited and the proc file system works.

 src/shellingham/posix/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/shellingham/posix/__init__.py b/src/shellingham/posix/__init__.py
index ec27b3a..1f4b80c 100644
--- a/src/shellingham/posix/__init__.py
+++ b/src/shellingham/posix/__init__.py
@@ -6,7 +6,7 @@ from .._consts import SHELL_NAMES
 
 def _get_process_mapping():
     system = platform.system()
-    if system == 'Linux':
+    if system in ('Linux', 'CYGWIN_NT-6.1'):
         from . import linux as impl
     else:
         from . import _default as impl

I think the "6.1" string may change a couple times a year. It may be better to do:

if system == 'Linux' or system.startswith('CYGWIN_NT'):
@uranusjr
Copy link
Member

uranusjr commented Jul 4, 2018

I wonder if it is a good idea to use /proc whenever it is available. Solution is up in #5 that should work on both Linux and Cygwin, but I wonder if it would break systems such as FreeBSD. Do they all have compatible /proc? I’ll need to find out.

@badboybeyer
Copy link
Author

It looks like the BSD4.4 children use /proc/$PID/status instead of /proc/$PID/stat.

old openbsd man page

modern freebsd manpage

Maybe write the module to:

try:
   proc()
except:
   ps()

@uranusjr
Copy link
Member

uranusjr commented Jul 6, 2018

Urrgh! Yeah I guess I need to revise the logic. A try-except is a good idea (but probably not a bare one).

@uranusjr uranusjr reopened this Jul 6, 2018
@techalchemy
Copy link
Member

Just handle the different structures of proc. There are only like 3 filesystems. It’s a finite space.

@uranusjr
Copy link
Member

uranusjr commented Jul 6, 2018

Okay I think we have two. What’s the third /facepalm

@uranusjr
Copy link
Member

uranusjr commented Jul 9, 2018

I decided to

  1. Try /proc (detect if it is Linux and BSD styles)
  2. If that fails, try ps
  3. If ps also fails, raise an error

We can add compatibility to more uncommon formats when someone actually wants them.

@uranusjr uranusjr closed this as completed Jul 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants