Skip to content

Commit

Permalink
Add some hack for non blocking waitpid Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
yuxiaomao committed Apr 18, 2024
1 parent 7f813dc commit 6e7d379
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Binary file modified hldebug-wrapper/lib/linux/hldebug.node
Binary file not shown.
12 changes: 11 additions & 1 deletion hldebug-wrapper/src/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
# include <sys/wait.h>
# include <sys/user.h>
# include <signal.h>
# include <errno.h>
# define USE_PTRACE
#endif

Expand Down Expand Up @@ -248,9 +249,18 @@ HL_API int hl_debug_wait( int pid, int *thread, int timeout ) {
return mdbg_session_wait(pid, thread, timeout);
# elif defined(USE_PTRACE)
int status;
int ret = waitpid(pid,&status,0);
// *** HACK ***
// usleep here is needed for a good result.
// Without it, waitpid can miss many stop event;
// With it, and more we wait, less we miss stop event.
usleep(100 * 1000);
int ret = waitpid(pid, &status, WNOHANG);
//printf("WAITPID=%X %X\n",ret,status);
*thread = ret;
if( ret == -1 && errno != EINTR )
return 3;
if( ret <= 0 )
return -1;
if( WIFEXITED(status) )
return 0;
if( WIFSTOPPED(status) ) {
Expand Down

1 comment on commit 6e7d379

@yuxiaomao
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need this hack for vscode extension, I don't know why waitpid(WNOHANG) can miss stop event on my VM 😢 . Maybe other thread is waiting for all child?
Another solution is to retrieving process state by reading /proc/<pid>/stat but I don't think it's much better hack.

Please sign in to comment.