Truss is often used while debugging "hung" processes, but if the target process really is not doing anything, then truss doesn't print anything either. This patch adds a 2-second timeout to the core loop, and if it fires, any threads waiting in a syscall will be printed.
Performance penalty: two setitimer() calls per traced syscall, plus the nested-loop search to determine how many pending syscalls there are. The pending syscall count could be aggregated into a summary variable and kept up-to-date by alloc_syscall() and free_syscall(), if needed.
Example output:
# simple trace of a sleep command $ truss -d sleep 4 [...] 0.099993429 cap_fcntls_limit(2,CAP_FCNTL_GETFL) ERR#78 'Function not implemented' 0.100991620 cap_enter() ERR#78 'Function not implemented' 0.102608113 sigaction(SIGINFO,{ 0x400cb0 SA_RESTART ss_t },{ SIG_DFL SA_RESTART ss_t }) = 0 (0x0) 2.105037303 nanosleep({ 4.000000000 },) ...sleeping 4.105016531 nanosleep({ 4.000000000 },{ 4.000000000 }) = 0 (0x0) 4.106558773 sigprocmask(SIG_BLOCK,{ SIGHUP|SIGINT|SIGQUIT|SIGKILL|SIGPIPE|SIGALRM|SIGTERM|SIGURG|SIGSTOP|SIGTSTP|SIGCONT|SIGCHLD|SIGTTIN|SIGTTOU|SIGIO|SIGXCPU|SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGINFO|SIGUSR1|SIGUSR2|SIGTHR },{ }) = 0 (0x0) 4.108041307 sigprocmask(SIG_SETMASK,{ },0x0) = 0 (0x0) [...] # trace an active radius daemon, showing that a threaded process can be traced, and all pending syscalls are printed (_umtx_op and kevent in this case): $ truss -dH -p $(pgrep radiusd) 101146: 2.000916627 kevent(4,0x0,0,,512,0x0) ...sleeping 101146: 4.105742028 kevent(4,0x0,0,{ 10,EVFILT_READ,0x0,0,0x47,0x803668b08 },512,0x0) = 1 (0x1) 101146: 4.106004130 recvfrom(10,"\^A+\0G",4,MSG_PEEK,{ AF_INET 127.0.0.1:32998 },0x7fffffffe820) = 4 (0x4) 101146: 4.106193837 recvfrom(10,"\^A+\0G",4,MSG_PEEK,{ AF_INET 127.0.0.1:32998 },0x7fffffffe724) = 4 (0x4) 101146: 4.106297587 recvfrom(10,"\^A+\0G\^XQ\M^Z\M-.\M-$\M-M\M-="...,71,0,{ AF_INET 127.0.0.1:32998 },0x7fffffffe724) = 71 (0x47) 101146: 4.106523467 getsockname(10,{ AF_INET 0.0.0.0:1812 },0x7fffffffe720) = 0 (0x0) 101146: 4.106666032 _umtx_op(0x684d18,UMTX_OP_SEM2_WAKE,0x0,0x0,0x0) = 0 (0x0) 101682: 4.106912044 mmap(0x0,2097152,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0x0) = 34500247552 (0x808600000) 101682: 4.107070112 wait4(0,0x7fffdfffdeb8,WNOHANG,0x0) ERR#10 'No child processes' 101682: 4.107286309 mmap(0x0,4096,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0x0) = 34366926848 (0x8006db000) 101682: 4.107526954 write(3,"Fri Jun 15 15:30:15 2018 : Info:"...,182) = 182 (0xb6) 101146: 4.440923540 kevent(4,0x0,0,{ },512,{ 0.333202000 }) = 0 (0x0) 101682: 6.441898153 _umtx_op(0x684d18,UMTX_OP_SEM2_WAIT,0x0,0x0,0x0) ...sleeping 101146: 6.441949765 kevent(4,0x0,0,,512,0x0) ...sleeping ^C