1 /* Copyright (c) 2003-2004, Roger Dingledine
2 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3 * Copyright (c) 2007-2021, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
8 * \brief Record this process's PID to disk.
12 #include "lib/process/pidfile.h"
14 #include "lib/log/log.h"
16 #ifdef HAVE_SYS_TYPES_H
17 #include <sys/types.h>
27 /** Write the current process ID, followed by NL, into <b>filename</b>.
28 * Return 0 on success, -1 on failure.
31 write_pidfile(const char *filename
)
35 if ((pidfile
= fopen(filename
, "w")) == NULL
) {
36 log_warn(LD_FS
, "Unable to open \"%s\" for writing: %s", filename
,
41 int pid
= (int)_getpid();
43 int pid
= (int)getpid();
46 if (fprintf(pidfile
, "%d\n", pid
) < 0)
48 if (fclose(pidfile
) < 0)