Your example is a C program. I'm guessing you're using gccgo to link with
equivalent C code. In which case your question has almost nothing to do
with Go. You need to ask the Linux community why your example results in a
defunct process that appears to have a live thread.

I do not believe you "understand defunct process mechanism". Because a
defunct process is one that does not have any executing threads. Yet you
still seem to think that Go, somehow, creates a process that is both
defunct and has an executing thread.

On Thu, Sep 10, 2020 at 10:08 PM Uday Kiran Jonnala <judayki...@gmail.com>
wrote:

> Thanks Kurtis for the reply. I understand defunct process mechanism.
>
> As I mentioned in the initial mail, [Correct me if I am wrong here], In a
> process if there is main thread and a detached thread created by main
> thread, when the main thread exits the process is kept in defunct state,
> since the created thread is still
> executing, I was thinking if we have such scenario in go runtime. That
> could be the reason I see this thread is waiting on futex and holding the
> file handles and causing the go process (kernel) not to send SIGCHLD to
> parent process.
>
> For example below case
>
> #include <stdio.h>
> #include <pthread.h>
> #include <unistd.h>
> #include <stdlib.h>
>
> void *thread_function(void *args)
> {
> printf("The is new thread! Sleep 20 seconds...\n");
> sleep(100);
> printf("Exit from thread\n");
> pthread_exit(0);
> }
>
> int main(int argc, char **argv)
> {
>  pthread_t thrd;
>  pthread_attr_t attr;
>  int res = 0;
>  res = pthread_attr_init(&attr);
>  res = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
>  res = pthread_create(&thrd, &attr, thread_function, NULL);
>  res = pthread_attr_destroy(&attr);
>  printf("Main thread. Sleep 5 seconds\n");
>  sleep(5);
>  printf("Exit from main process\n");
>  pthread_exit(0);
> }
>
> ujonnala@ ~/mycode/go () $ ps -T
>    PID   SPID TTY          TIME CMD
>  43635  43635 pts/29   00:00:00 a.out <defunct>
>  43635  43638 pts/29   00:00:00 a.out
>
> Due to the detached thread still executing the process left in defunt
> state.
>
> Thanks for checking on this, I will see if we can reproduce my situation
> on a newer kernel.
>
> Thanks & Regards,
> Uday Kiran
>
> On Thursday, September 10, 2020 at 9:49:06 PM UTC-7 Kurtis Rader wrote:
>
>> On Thu, Sep 10, 2020 at 9:25 PM Uday Kiran Jonnala <juday...@gmail.com>
>> wrote:
>>
>>> Thanks for the reply. We are fixing the issue. But the point I wanted to
>>> bring it up here is the issue of a thread causing the go process to be in
>>> defunct state.
>>>
>>
>> Any thread can cause the go process to enter the "defunct" state. For
>> example, by calling os.Exit(), or panic(), or causing a signal to be
>> delivered that terminates the process (e.g., SIGSEGV).
>>
>>
>>> My kernel version is
>>> Linux version 4.14.175-1.nutanix.20200709.el7.x86_64 (dev@ca4b0551898c)
>>> (gcc version 7.3.1 20180303 (Red Hat 7.3.1-5) (GCC)) #1 SMP Fri Jul 10
>>> 02:17:54 UTC 2020
>>>
>>
>> Is that the output of `uname -a`? It seems to suggest you're using CentOS
>> provided by the https://www.nutanix.com/go/linux-on-ahv cloud
>> environment. So we've established you are using Linux with kernel version
>> 4.14. A kernel that is now three years old. I don't have anything like it
>> installed on any of my virtual machines so I can't explore how it handles
>> defunct processes. But my prior point stands: A "defunct" process is one
>> that has been terminated but whose parent process has not reaped its exit
>> status. Either that parent process has a bug (the most likely explanation)
>> or your OS has a bug.
>>
>> --
>> Kurtis Rader
>> Caretaker of the exceptional canines Junior and Hank
>>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/ad4843e1-f7d1-43ae-8091-579bc61527fdn%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/ad4843e1-f7d1-43ae-8091-579bc61527fdn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CABx2%3DD-AA6N7jw2%3DR5gamWoewpokuRzVz_OSo70jGrWQ%2Bpj7DA%40mail.gmail.com.

Reply via email to