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

Processes get defunct on Cygwin #13

Closed
ismail opened this issue Jun 5, 2015 · 25 comments
Closed

Processes get defunct on Cygwin #13

ismail opened this issue Jun 5, 2015 · 25 comments

Comments

@ismail
Copy link

@ismail ismail commented Jun 5, 2015

This is originally reported at https://cygwin.com/ml/cygwin/2015-05/msg00314.html , how to reproduce. Build and compile the following Go program

package main

import (
"fmt"
"time"
)

func main() {
for i := 0; ; i++ {
fmt.Println(i)
time.Sleep(500*time.Millisecond)
}
}

Run it in one window and try to switch, it will eventually switch but will take a lot of time. And if you wait long enough it'll put title on the window. I have this semi-regularly happening with ssh running under a tmux window.

@nicm
Copy link
Member

@nicm nicm commented Jun 5, 2015

Can you reproduce it with Bash instead of Go and give me the script please?

@nicm
Copy link
Member

@nicm nicm commented Jun 5, 2015

Also please tell me the libevent versions you are using with tmux 1.9 and 2.0? Are they the same?

@ismail
Copy link
Author

@ismail ismail commented Jun 6, 2015

  1. Can't seem to reproduce with Bash, I suspect this has something to do with native (non-cygwin) Windows programs.
  2. libevent version is 2.0.21, but I tested with 2.0.22 with no success.
  3. I didn't try myself to be sure but the initial report says tmux 1.9a works fine and this is a 2.0 regression.
@ismail
Copy link
Author

@ismail ismail commented Jun 6, 2015

A very easy reproducer, run cmd.exe in one window, and tmux goes to defunct state soon and gets really really slow.

@nicm
Copy link
Member

@nicm nicm commented Jun 6, 2015

Can you try this please and see if the problem goes away?

diff --git a/osdep-cygwin.c b/osdep-cygwin.c
index 91bc5fc..061be7a 100644
--- a/osdep-cygwin.c
+++ b/osdep-cygwin.c
@@ -35,6 +35,8 @@ osdep_get_name(int fd, unused char *tty)
    int  ch;
    pid_t    pgrp;

+   return NULL;
+
    if ((pgrp = tcgetpgrp(fd)) == -1)
        return (NULL);

@@ -68,6 +70,8 @@ osdep_get_cwd(int fd)
    pid_t        pgrp;
    ssize_t      n;

+   return NULL;
+
    if ((pgrp = tcgetpgrp(fd)) == -1)
        return (NULL);

@nicm
Copy link
Member

@nicm nicm commented Jun 6, 2015

If it does, please try moving the returns you added down below the tcgetpgrp lines like this:

    if ((pgrp = tcgetpgrp(fd)) == -1)
        return (NULL);
    return NULL;

And see if the problem comes back.

@ismail
Copy link
Author

@ismail ismail commented Jun 6, 2015

In both cases bug is gone and tmux is really responsive as expected.

@nicm
Copy link
Member

@nicm nicm commented Jun 6, 2015

If you remove the return from osdep_get_cwd but not osdep_get_name, does the problem come back?

@ismail
Copy link
Author

@ismail ismail commented Jun 6, 2015

Yes the problem comes back.

@nicm
Copy link
Member

@nicm nicm commented Jun 6, 2015

Ok, it sounds like there is a problem with /proc/*/cmdline with native processes, I suspect either Cygwin has a bug which is making tmux have to read a lot of data from the cmdline file, or Cygwin is having to go off and do a lot of slow, extra work that it doesn't have to do for Cygwin processes. I expect you would have mentioned if tmux did not actually rename the window to cmd.exe so I suspect the second idea is true.

I suggest you report this to Cygwin. If they can't or won't fix it, I would be fine with making tmux disable automatic-rename for native processes, but I need to know if there is a way to detect them (is there something in /proc to look at?).

As a workaround, you can just turn off automatic-rename either globally with -g or just for the window where you are running the native process.

@ismail
Copy link
Author

@ismail ismail commented Jun 6, 2015

Thanks but I can't reproduce it with usual tools, I run cmd.exe under bash and

cat /proc/6784/cmdline

So thats where the defunct title is coming. It takes 1s to get that output (quite slow compared to the native cygwin procs.) I'll try to find out if there is a way to find if a program is native-cygwin or not.

@ismail
Copy link
Author

@ismail ismail commented Jun 6, 2015

Btw with "set -g automatic-rename off" there is a noticable slowdown.

@nicm
Copy link
Member

@nicm nicm commented Jun 6, 2015

A second is too long, tmux does this for every window twice a second.

-------- Original message --------
From: İsmail Dönmez notifications@github.com
Date:06/06/2015 10:35 (GMT+00:00)
To: tmux/tmux tmux@noreply.github.com
Cc: Nicholas Marriott nicholas.marriott@gmail.com
Subject: Re: [tmux] Processes get defunct on Cygwin (#13)

Thanks but I can't reproduce it with usual tools, I run cmd.exe under bash and

cat /proc/6784/cmdline
So thats where the defunct title is coming. It takes 1s to get that output (quite slow compared to the native cygwin procs.) I'll try to find out if there is a way to find if a program is native-cygwin or not.


Reply to this email directly or view it on GitHub.

@ismail
Copy link
Author

@ismail ismail commented Jun 6, 2015

Well, if it reads on Cygwin then it can decide its non-cygwin program and stop.

@ismail
Copy link
Author

@ismail ismail commented Jun 6, 2015

Is there a way to also stop cwd reading for current process? Thats also very slow for non-Cygwin apps.

@nicm
Copy link
Member

@nicm nicm commented Jun 6, 2015

No because then when you stop the program it wouldn't know to start again. It needs something fast it can check to tell it not to open cmdline at all. Or better it needs it not to be so ridiculously slow, ask the Cgywin ML.

@nicm
Copy link
Member

@nicm nicm commented Jun 6, 2015

Any way to detect native processes can be used for both cmd and cwd. But there is no point in adding workarounds if they could fix it in Cgywin :-).

@ismail
Copy link
Author

@ismail ismail commented Jun 6, 2015

I am writing to cygwin list, hopefully this can be fixed. Thanks a lot for insight!

@ismail ismail closed this Jun 8, 2015
@nicm
Copy link
Member

@nicm nicm commented Jun 8, 2015

Ok what does automatic-rename rename the windows with native processes in to now?

@ismail
Copy link
Author

@ismail ismail commented Jun 8, 2015

For native Windows processes it shows "" now.

@nicm
Copy link
Member

@nicm nicm commented Jun 8, 2015

Alright well I guess that will do. Thanks for getting this fixed.

@ismail
Copy link
Author

@ismail ismail commented Jun 8, 2015

Thanks for the clues :)

@ismail
Copy link
Author

@ismail ismail commented Jun 9, 2015

Just an update, with https://cygwin.com/git/gitweb.cgi?p=newlib-cygwin.git;a=commitdiff;h=575ec00a43ae3bbc84d5dab1233c3f95fdad18d0 Cygwin now shows real cmdline and cwd for non-native cygwin processes.

@lock
Copy link

@lock lock bot commented Feb 17, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Feb 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants