diff --git a/src/main.cc b/src/main.cc
index 17d6dda2e6db7f7e2b7bae8417b056960606d16e..e7cbd93488d105524e59ac6a25fbac7c6bae45b5 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -89,7 +89,7 @@
 #include "core/clock_lowres.h"
 #include "lua/utils.h"
 
-static pid_t master_pid = getpid();
+static pid_t master_pid = -1;
 static struct pidfh *pid_file_handle;
 static char *script = NULL;
 static char *pid_file = NULL;
@@ -642,6 +642,10 @@ extern "C"
 int
 tarantool_main(int argc, char **argv, void (*cb)(void *), void *cb_data)
 {
+	// Picodata forks the process and only the child runs tarantool_main.
+	// Therefore master_pid must be set here instead of the static memory,
+	// so that the resources are cleaned up at the end
+	master_pid = getpid();
 	/* set locale to make iswXXXX function work */
 	if (setlocale(LC_CTYPE, "C.UTF-8") == NULL &&
 	    setlocale(LC_CTYPE, "en_US.UTF-8") == NULL &&