Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the signal processing of PostgreSQL in Windows system?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how the signal processing of PostgreSQL in the Windows system is, and the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

In fact, the signal processing of PostgreSQL under Windows can only be described as simulation or code encapsulation. When it is called, it also looks like a pgsignal function, which realizes the cross-platform of the code, but it has nothing to do with the signal in implementation. After all, Windows does not have this feature.

1. The Windows code of PostgreSQL is in the function save_backend_variables:

# ifdef WIN32 param- > PostmasterHandle = PostmasterHandle; if (! write_duplicated_handle (& param- > initial_signal_pipe, pgwin32_create_signal_listener (childPid), childProcess)) return false;#else

The following is about the two functions here, and the API used can consult the Microsoft documentation on its own.

2. Create named pipes

The function pgwin32_create_signal_listener is to create a named pipe

Snprintf (pipename, sizeof (pipename), "\.\ pipe\\ pgsignal_%u", (int) pid); pipe = CreateNamedPipe (pipename, PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, 16, 16, 1000, NULL)

3. Copy the pipe handle

In the function write_duplicated_handle:

If (! DuplicateHandle (GetCurrentProcess (), src, childProcess, & hChild, 0, TRUE, DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS))

This copied handle is passed to the newly created back-end process via param.

4. Signal function under Windows

Pqsigfuncpqsignal (int signum, pqsigfunc handler) {pqsigfunc prevfunc; if (signum > = PG_SIGNAL_COUNT | | signum < 0) return SIG_ERR; prevfunc = pg_signal_ Array [signum]; pg_signal_ Array [signum] = handler; return prevfunc;}

There is an array of signal processing functions, and the function of pqsignal is to record which signal is processed.

5. Kill function under Windows

# define kill (pid,sig) pgkill (pid,sig) extern int pgkill (int pid, int sig)

In pgkill, use the named pipe created above

Snprintf (pipename, sizeof (pipename), "\\.\ pipe\\ pgsignal_%u", pid); if (CallNamedPipe (pipename, & sigData, 1, & sigRet, 1, & bytes, 1000))

Write the signal to a pipe, such as SIGHUP.

6. Signal processing thread

At startup, create a thread that specifically handles named pipe events:

/ * Create thread for handling signals * / signal_thread_handle = CreateThread (NULL, 0, pg_signal_thread, NULL, 0, NULL)

7. Signal processing of back-end processes

Function pg_signal_dispatch_thread (src/backend/port/win32/signal.c):

/ * Create thread for handling signals * / signal_thread_handle = CreateThread (NULL, 0, pg_signal_thread, NULL, 0, NULL); Pg_queue_signal (sigNum); about how the signal processing of PostgreSQL in the Windows system is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report