#41 zsh.exe hang

open
nobody
None
5
2008-04-21
2008-04-21
Anonymous
No

Hi,

I am facing a problem in unxutils provided zsh source compiled zsh.exe.

Say a shell script 'test.sh.' is being executed under sh.exe ( renamed zsh.exe to emulate BASH ). This script sometimes hangs in sh.exe, not consuming any cpu cycle. On running a debug version of sh.exe and checking with Process Exporer I found the following information

1) The parent process to hung sh.exe has the following stack trace in each of its running threads -

Thread-1

!DefWindowProcW+0x6b
ntdll.dll!KiFastSystemCallRet
!WaitForSingleObject+0x12
!sigchild_thread+0x1a
!GetModuleFileNameA+0x1b4
===================================================

Thread-2 (referred as main-thread in my explanation )

!DefWindowProcW+0x6b
ntdll.dll!KiFastSystemCallRet
!nt_read+0x79
!nt_fgetc+0x1e
!readoutput+0x4f
!getoutput+0x21f
!stringsubst+0x342
!prefork+0x121
!addvars+0x115
!execcmd+0x570
!execpline2+0x85
!execpline+0x1ab
!execlist+0xfb
!execif+0x9c
!execcmd+0x15a2
!execpline2+0x85
!execpline+0x1ab
!execlist+0xfb
!execif+0x9c
!execcmd+0x15a2
!execpline2+0x85
!execpline+0x1ab
!execlist+0xfb
!doshfunc+0x293
!execshfunc+0x1ad
!execcmd+0x16be
!execpline2+0x85
!execpline+0x1ab
!execlist+0xfb
!execif+0x9c
!execcmd+0x15a2
!execpline2+0x85
!execpline+0x1ab
!execlist+0xfb
!doshfunc+0x293
!execshfunc+0x1ad
!execcmd+0x16be
!execpline2+0x85
!execpline+0x1ab
!execlist+0xfb
!doshfunc+0x293
!execshfunc+0x1ad
!execcmd+0x16be
!execpline2+0x85
!execpline+0x1ab
!execlist+0xfb
!execif+0x9c
!execcmd+0x15a2
!execpline2+0x85
!execpline+0x1ab
!execlist+0xfb
!execif+0x9c
!execcmd+0x15a2
!execpline2+0x85
!execpline+0x1ab
!execlist+0xfb
!loop+0xbe
!main+0x214
!mainCRTStartup+0x143
!silly_entry+0x113
!RegisterWaitForInputIdle+0x49

Parent process spawns a intermediate 'sh.exe' process to carry out execution of shell commands. To wait for this process, get the exit code and update the job table ( maintained internally by 'sh.exe' interpreter), a separate thread is created which we see in the above stack trace as 'Thread-1'. This thread waits for an object ( process handle ) to be
signaled using'WaitForSingleObject(..)' call indefinitely. It expects the intermediate 'sh.exe' process to signal it by exiting with a exit code.
On the other hand, the main thread ( Thread-2 ) waits in the read(..) call to get the output of the command executed by intermediate 'sh.exe' throught stdout.

2) The stack trace of hung 'sh.exe' ( Intermediate sh.exe ) is as follows:

Child - Intermediate sh......

!DefWindowProcW+0x6b
ntdll.dll!KiFastSystemCallRet
!UnregisterClassW+0x32
!Ordinal330+0x5660
!InitCommonControlsEx+0x5ee
!InitCommonControlsEx+0x5b4
!Ordinal285+0x3501
ntdll.dll!LdrInitializeThunk+0x29
ntdll.dll!LdrShutdownProcess+0x142
!IsValidLocale+0x8eb
!ExitProcess+0x14
!nt_execve_wrapped+0x51f
!nt_execve+0x14
!zexecve+0x100
!execute+0x6b1
!execcmd+0x1925
!execpline2+0x85
!execpline2+0x238
!execpline+0x1ab
!execlist+0xfb
!getoutput+0x29c
!stringsubst+0x342
!prefork+0x121
!addvars+0x115
!execcmd+0x570
!execpline2+0x85
!execpline+0x1ab
!execlist+0xfb
!execif+0x9c
!execcmd+0x15a2
!execpline2+0x85
!execpline+0x1ab
!execlist+0xfb
!execif+0x9c
!execcmd+0x15a2
!execpline2+0x85
!execpline+0x1ab
!execlist+0xfb
!doshfunc+0x293
!execshfunc+0x1ad
!execcmd+0x16be
!execpline2+0x85
!execpline+0x1ab
!execlist+0xfb
!execif+0x9c
!execcmd+0x15a2
!execpline2+0x85
!execpline+0x1ab
!execlist+0xfb
!doshfunc+0x293
!execshfunc+0x1ad
!execcmd+0x16be
!execpline2+0x85
!execpline+0x1ab
!execlist+0xfb
!doshfunc+0x293
!execshfunc+0x1ad
!execcmd+0x16be
!execpline2+0x85
!execpline+0x1ab
!execlist+0xfb
!execif+0x9c
!execcmd+0x15a2
!execpline2+0x85
!execpline+0x1ab
!execlist+0xfb
!execif+0x9c
!execcmd+0x15a2
!execpline2+0x85
!execpline+0x1ab
!execlist+0xfb
!loop+0xbe
!main+0x214
!mainCRTStartup+0x143
!silly_entry+0x113
!RegisterWaitForInputIdle+0x49

This is an intermediate 'sh.exe' spawned to carry out the request of parent 'sh.exe' in executing shell commands. Once the shell command is executed, the intermmediate 'sh.exe' tries to exit with the exit code
obtained during the execution of shell command. During this process it hangs internally in 'ExitProcess(..)' call. Because of this, the parent 'sh.exe''s Thread-1 waiting for the intermediate 'sh.exe' process to signal is also hung.

In short, ExitProcess(..) call of intermediate 'sh.exe', WaitForSingleObject(..) of parent's Thread-1 and parent's main-thread in read(..) is deadlocked internally in their system calls.

This problem happens in only one developer machine here and many see at client's place. I was thinking if leaving the file handles ( called as fds in sh.exe ) and trying to ExitProcess(..) can hang sh.exe. But in
real when process exits the handles opened should be closed.

Please help me if you have any idea for such a weird problem.

Discussion


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks