+/*
+ * Copyright (C) 2010 Timo Kokkonen <timo.t.kokkonen@iki.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
{
FILE *file;
char path[512];
- int ret;
+ int ret, i;
snprintf(path, sizeof(path), "/proc/%d/task/%d/cmdline", pid, tid);
file = fopen(path, "rb");
cmdline[ret - 1] = 0;
fclose(file);
+ /*
+ * Process arguments are separated by NULL bytes. Replace
+ * these with spacese so that the arguments become visible
+ * too.
+ */
+ for (i = 0; i < ret - 1; i++)
+ if (cmdline[i] == '\0')
+ cmdline[i] = ' ';
+
return ret > 0 ? 0 : -1;
}