













































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Focused on libuv, the asynchronous I/O library powering Node.js. Exam topics cover event loops, thread pools, filesystem operations, TCP/UDP communication, async patterns, handles/requests, cross-platform abstractions, concurrency management, and memory handling. Candidates debug complex async flows, build native modules, and analyze event-loop performance characteristics.
Typology: Exams
1 / 85
This page cannot be seen from the preview
Don't miss anything!














































































Question 1. Which libuv component is primarily responsible for abstracting platform‑specific I/O notification mechanisms such as epoll, kqueue, and IOCP? A) uv_loop_t B) uv_handle_t C) uv_backend_t D) uv_req_t Answer: C Explanation: uv_backend_t (internal to libuv) selects the appropriate OS‑specific backend (epoll, kqueue, IOCP, etc.) to provide a uniform event notification interface. Question 2. In libuv terminology, what is the difference between a “handle” and a “request”? A) Handles are short‑lived, requests are long‑lived. B) Handles represent persistent resources; requests represent one‑time operations. C) Handles are thread‑safe; requests are not. D) Handles are only for networking; requests are only for file I/O. Answer: B Explanation: Handles (e.g., uv_tcp_t, uv_timer_t) exist for the lifetime of a resource, while requests (e.g., uv_write_t, uv_getaddrinfo_t) are created for a single operation and freed after completion. Question 3. Which uv_run mode processes events until there are no active handles or requests left? A) UV_RUN_DEFAULT B) UV_RUN_ONCE C) UV_RUN_NOWAIT D) UV_RUN_BLOCKING Answer: A
Explanation: UV_RUN_DEFAULT runs the loop repeatedly until there are no active handles or requests, then returns. Question 4. During which phase of the libuv event loop are timer callbacks that have reached their deadline executed? A) Prepare phase B) Timer phase C) Poll phase D) Check phase Answer: B Explanation: The Timer phase is the first phase of each loop iteration and processes uv_timer_t handles whose timeout has expired. Question 5. Which libuv handle type is used to receive notifications when a file system path changes (e.g., a file is modified)? A) uv_fs_event_t B) uv_fs_poll_t C) uv_prepare_t D) uv_idle_t Answer: A Explanation: uv_fs_event_t watches for file system events such as modifications, creations, or deletions, delivering callbacks when they occur. Question 6. What environment variable controls the size of libuv’s internal thread pool? A) UV_THREADPOOL_SIZE B) LIBUV_POOL_SIZE C) UV_WORKERS
Answer: B Explanation: UV_TCP_NODELAY disables the Nagle algorithm, allowing small packets to be sent immediately. Question 10. Which of the following libuv handles is used for inter‑process communication on Unix domain sockets? A) uv_pipe_t B) uv_tcp_t C) uv_tty_t D) uv_udp_t Answer: A Explanation: uv_pipe_t abstracts both named pipes on Windows and Unix domain sockets on POSIX systems for IPC. Question 11. When using uv_getaddrinfo(), which callback receives the resolved address information? A) uv_getaddrinfo_cb B) uv_resolve_cb C) uv_dns_cb D) uv_lookup_cb Answer: A Explanation: The uv_getaddrinfo_cb is invoked with the results of the asynchronous DNS resolution performed by uv_getaddrinfo(). Question 12. Which libuv phase runs immediately after the poll phase, regardless of whether any I/O events occurred?
A) Prepare phase B) Check phase C) Close phase D) Idle phase Answer: B Explanation: The Check phase is always executed after the poll phase, allowing users to schedule callbacks that must run after I/O processing. Question 13. Which libuv function is used to close a handle and ensure its close callback is called? A) uv_close() B) uv_shutdown() C) uv_stop() D) uv_cleanup() Answer: A Explanation: uv_close() marks a handle for closing; once the loop reaches the Close callbacks phase, the user‑provided close callback is executed. Question 14. What is the purpose of uv_async_t in libuv? A) To perform asynchronous file reads. B) To send a signal from another thread to the event loop. C) To schedule a timer callback. D) To create a non‑blocking TCP connection. Answer: B Explanation: uv_async_t provides a thread‑safe way to wake up the event loop and invoke a callback from another thread.
Question 18. Which libuv error code indicates that an operation would block on a non‑blocking socket? A) UV_EAGAIN B) UV_EWOULDBLOCK C) UV_EBLOCKED D) UV_EINPROGRESS Answer: A Explanation: UV_EAGAIN is the libuv mapping of the POSIX EAGAIN/EWOULDBLOCK error, meaning the operation would block. Question 19. What does uv_hrtime() return? A) Current time in milliseconds since the Unix epoch. B) High‑resolution monotonic time in nanoseconds. C) CPU usage percentage. D) Number of event loop iterations. Answer: B Explanation: uv_hrtime() provides a monotonic clock with nanosecond precision, suitable for performance measurements. Question 20. Which libuv handle type is used to watch for changes to a child process’s exit status? A) uv_process_t B) uv_signal_t C) uv_child_t D) uv_exit_t Answer: A
Explanation: uv_process_t represents a spawned child process; its exit callback is invoked when the child terminates. Question 21. In libuv, what does the UV_RUN_ONCE mode do? A) Runs the loop until there are no active handles. B) Executes a single poll cycle and then returns. C) Returns immediately without processing any events. D) Runs the loop forever. Answer: B Explanation: UV_RUN_ONCE processes events that are ready, performs one poll, then returns control to the caller. Question 22. Which libuv function is used to set a TCP handle’s keep‑alive option? A) uv_tcp_keepalive() B) uv_tcp_set_keepalive() C) uv_tcp_keepalive_set() D) uv_tcp_enable_keepalive() Answer: A Explanation: uv_tcp_keepalive() enables or disables keep‑alive and optionally sets the initial delay. Question 23. What is the default size of libuv’s thread pool if UV_THREADPOOL_SIZE is not defined? A) 2 B) 4 C) 8 D) 16
Explanation: uv_loop_close() shuts down the loop, ensuring all handles are closed and memory is released; it must be called after uv_run returns. Question 27. Which libuv function schedules a callback to be called after a specified timeout? A) uv_timer_start() B) uv_timeout_start() C) uv_delay() D) uv_set_timeout() Answer: A Explanation: uv_timer_start() creates or restarts a uv_timer_t that fires after the given timeout (and optionally repeats). Question 28. How does libuv indicate that a file descriptor is ready for reading? A) By invoking the read callback registered with uv_poll_start(). B) By returning UV_EREADABLE from uv_run(). C) By setting a flag in uv_handle_t. D) By posting a message to the thread pool. Answer: A Explanation: uv_poll_start() registers interest in readability (or writability); when the OS signals readiness, the poll callback is invoked. Question 29. Which libuv function is used to change the priority of a thread created with uv_thread_create()? A) uv_thread_setpriority() B) uv_thread_priority() C) uv_thread_set_sched() D) uv_thread_set_priority()
Answer: B Explanation: uv_thread_priority() adjusts the scheduling priority of a libuv thread. Question 30. In libuv, what is the purpose of uv_barrier_t? A) To synchronize a fixed number of threads at a specific point. B) To protect a shared resource from concurrent access. C) To limit the number of concurrent DNS lookups. D) To delay execution of a timer until a condition is met. Answer: A Explanation: uv_barrier_t allows a set of threads to wait until all have reached the barrier, then they all proceed. Question 31. Which libuv API is used to perform an asynchronous file read operation? A) uv_fs_read() B) uv_file_read() C) uv_read_file() D) uv_async_read() Answer: A Explanation: uv_fs_read() schedules a read request on a file descriptor; the result is delivered via a callback. Question 32. What does the UV_HANDLE_TYPE macro return for a uv_tcp_t handle? A) UV_TCP B) UV_STREAM C) UV_HANDLE_TCP D) UV_HANDLE_TYPE_TCP Answer: A
Answer: A Explanation: uv_udp_send() takes a const struct sockaddr* that describes the remote IP and port for the datagram. Question 36. Which libuv function converts a nanosecond value returned by uv_hrtime() to milliseconds? A) uv_hrtime() already returns milliseconds. B) uv_hrtime_to_ms() C) No built‑in function; you divide by 1e6. D) uv_time_ms() Answer: C Explanation: libuv does not provide a direct conversion; the user must divide the nanosecond value by 1,000,000 to obtain milliseconds. Question 37. What does uv_mutex_lock() return on success? A) 0 B) 1 C) UV_OK D) UV_SUCCESS Answer: A Explanation: Like most POSIX‑style APIs, uv_mutex_lock() returns 0 on success and a non‑zero error code on failure. Question 38. Which libuv API is used to watch for changes to a directory’s contents (e.g., file creation) on Windows where uv_fs_event_t is not reliable? A) uv_poll_t B) uv_fs_poll_t
C) uv_dirwatch_t D) uv_file_event_t Answer: B Explanation: uv_fs_poll_t polls the file system at a regular interval and works reliably across platforms, including Windows. Question 39. In the libuv event loop, which phase is executed even if there are no active handles? A) Close callbacks phase B) Prepare phase C) Idle phase (if an uv_idle_t is active) D) Poll phase Answer: C Explanation: The idle phase runs when there are no pending I/O events but at least one uv_idle_t handle is active. Question 40. Which libuv function registers a callback to be invoked when a particular signal (e.g., SIGTERM) is received? A) uv_signal_start() B) uv_signal_init() C) uv_signal_register() D) uv_signal_set() Answer: A Explanation: uv_signal_start() takes a uv_signal_t handle, a callback, and the signal number to monitor. Question 41. What does uv_is_active(handle) indicate?
Question 44. Which libuv function is used to schedule a callback that runs after all I/O callbacks but before the loop checks for new events? A) uv_check_start() B) uv_prepare_start() C) uv_idle_start() D) uv_poll_start() Answer: A Explanation: uv_check_start() registers a uv_check_t handle whose callback runs after polling and before the loop proceeds to the next iteration. Question 45. What does uv_tcp_bind() do? A) Connects a client socket to a remote address. B) Associates a TCP handle with a local address and port. C) Starts listening for incoming connections. D) Sets the TCP socket to non‑blocking mode. Answer: B Explanation: uv_tcp_bind() binds a uv_tcp_t to a local sockaddr, preparing it for listen() or connect(). Question 46. Which libuv function creates a new event loop instance? A) uv_loop_new() B) uv_loop_init() C) uv_new_loop() D) uv_loop_create() Answer: B Explanation: uv_loop_init() initializes a uv_loop_t structure; the caller provides storage for the loop.
Question 47. In libuv, which error code corresponds to “operation not supported”? A) UV_ENOSYS B) UV_EOPNOTSUPP C) UV_ENOTSUP D) UV_EUNSUPPORTED Answer: B Explanation: UV_EOPNOTSUPP maps to POSIX EOPNOTSUPP, indicating the operation is not supported on the current platform. Question 48. Which libuv API can be used to retrieve a human‑readable string for a libuv error code? A) uv_strerror_r() B) uv_err_name() C) uv_strerror() D) uv_error_string() Answer: C Explanation: uv_strerror(int err) returns a const char* describing the error. Question 49. What does uv_ref() do when called on a handle? A) Increments the reference count, preventing the loop from exiting while the handle is active. B) Increases the priority of the handle’s callbacks. C) Registers the handle with the thread pool. D) Marks the handle as closed. Answer: A Explanation: uv_ref() tells the loop to keep running as long as the handle is alive; uv_unref() does the opposite.
Explanation: uv_stop() causes uv_run() to return after the current iteration completes, even if there are still active handles. Question 53. Which libuv function creates a new timer handle? A) uv_timer_init() B) uv_timer_new() C) uv_timer_create() D) uv_timer_start() Answer: A Explanation: uv_timer_init() initializes a uv_timer_t within a loop; the handle can then be started with uv_timer_start(). Question 54. In libuv, which callback signature is used for uv_signal_t? A) void (uv_signal_cb)(uv_signal_t handle, int signum) B) void (uv_signal_cb)(uv_signal_t handle) C) void (uv_signal_cb)(int signum) D) void (uv_signal_cb)(uv_loop_t* loop, int signum) Answer: A Explanation: The signal callback receives the handle and the signal number. Question 55. Which libuv API can be used to retrieve the current loop’s backend name (e.g., "epoll")? A) uv_backend_name() B) uv_loop_backend() C) uv_get_backend() D) uv_backend_type() Answer: A
Explanation: uv_backend_name() returns a const char* indicating which backend implementation the loop is using. Question 56. What does uv_tcp_getsockname() retrieve? A) The remote address of a connected TCP socket. B) The local address the socket is bound to. C) The default DNS server. D) The TCP socket’s current state (LISTEN, ESTABLISHED). Answer: B Explanation: uv_tcp_getsockname() obtains the sockaddr that the TCP handle is bound to locally. Question 57. Which libuv function is used to schedule a callback that runs repeatedly at a fixed interval? A) uv_timer_start() with repeat argument > 0 B) uv_interval_start() C) uv_repeat_start() D) uv_set_interval() Answer: A Explanation: uv_timer_start() takes a repeat parameter; if non‑zero, the timer fires repeatedly after each interval. Question 58. Which libuv macro checks whether a handle is closing? A) uv_is_closing(handle) B) uv_handle_closing(handle) C) uv_handle_is_closing(handle) D) uv_is_handle_closing(handle)