2 * $Header: /cvsroot/pgpool/pgpool-II/pcp/pcp_proc_info.c,v 1.3 2008/12/31 10:25:40 t-ishii Exp $
4 * pgpool: a language independent connection pool server for PostgreSQL
5 * written by Tatsuo Ishii
7 * Copyright (c) 2003-2008 PgPool Global Development Group
9 * Permission to use, copy, modify, and distribute this software and
10 * its documentation for any purpose and without fee is hereby
11 * granted, provided that the above copyright notice appear in all
12 * copies and that both that copyright notice and this permission
13 * notice appear in supporting documentation, and that the name of the
14 * author not be used in advertising or publicity pertaining to
15 * distribution of the software without specific, written prior
16 * permission. The author makes no representations about the
17 * suitability of this software for any purpose. It is provided "as
18 * is" without express or implied warranty.
20 * Client program to send "process info" command.
30 static void usage(void);
31 static void myexit(ErrorCode e);
34 main(int argc, char **argv)
37 char host[MAX_DB_HOST_NAMELEN];
39 char user[MAX_USER_PASSWD_LEN];
40 char pass[MAX_USER_PASSWD_LEN];
42 ProcessInfo *process_info;
46 while ((ch = getopt(argc, argv, "hd")) != -1) {
65 pcp_errorstr(errorcode);
69 timeout = atol(argv[0]);
72 pcp_errorstr(errorcode);
76 if (strlen(argv[1]) >= MAX_DB_HOST_NAMELEN)
79 pcp_errorstr(errorcode);
82 strcpy(host, argv[1]);
85 if (port <= 1024 || port > 65535)
88 pcp_errorstr(errorcode);
92 if (strlen(argv[3]) >= MAX_USER_PASSWD_LEN)
95 pcp_errorstr(errorcode);
98 strcpy(user, argv[3]);
100 if (strlen(argv[4]) >= MAX_USER_PASSWD_LEN)
102 errorcode = INVALERR;
103 pcp_errorstr(errorcode);
106 strcpy(pass, argv[4]);
108 processID = atoi(argv[5]);
111 errorcode = INVALERR;
112 pcp_errorstr(errorcode);
116 pcp_set_timeout(timeout);
118 if (pcp_connect(host, port, user, pass))
120 pcp_errorstr(errorcode);
124 if ((process_info = pcp_process_info(processID, &array_size)) == NULL)
126 pcp_errorstr(errorcode);
131 for (i = 0; i < array_size; i++)
133 if (process_info->connection_info[i].database[0] == '\0')
136 printf("%s %s %ld %ld %d %d %d\n",
137 process_info->connection_info[i].database,
138 process_info->connection_info[i].user,
139 process_info->start_time,
140 process_info->connection_info[i].create_time,
141 process_info->connection_info[i].major,
142 process_info->connection_info[i].minor,
143 process_info->connection_info[i].counter);
156 fprintf(stderr, "pcp_proc_info - display a pgpool-II child process' information\n\n");
157 fprintf(stderr, "Usage: pcp_proc_info [-d] timeout hostname port# username password PID\n");
158 fprintf(stderr, "Usage: pcp_proc_info -h\n\n");
159 fprintf(stderr, " -d - enable debug message (optional)\n");
160 fprintf(stderr, " timeout - connection timeout value in seconds. command exits on timeout\n");
161 fprintf(stderr, " hostname - pgpool-II hostname\n");
162 fprintf(stderr, " port# - pgpool-II port number\n");
163 fprintf(stderr, " username - username for PCP authentication\n");
164 fprintf(stderr, " password - password for PCP authentication\n");
165 fprintf(stderr, " PID - PID of a child process to get information for\n");
166 fprintf(stderr, " -h - print this help\n");