1/* pwdx.c - report current directory of a process. 2 * 3 * Copyright 2013 Lukasz Skalski <l.skalski@partner.samsung.com> 4 5USE_PWDX(NEWTOY(pwdx, "<1a", TOYFLAG_USR|TOYFLAG_BIN)) 6 7config PWDX 8 bool "pwdx" 9 default y 10 help 11 usage: pwdx PID... 12 13 Print working directory of processes listed on command line. 14*/ 15 16#include "toys.h" 17 18void pwdx_main(void) 19{ 20 char **optargs; 21 22 for (optargs = toys.optargs; *optargs; optargs++) { 23 char *path = toybuf; 24 25 sprintf(toybuf, "/proc/%d/cwd", atoi(*optargs)); 26 if (!readlink0(path, toybuf, sizeof(toybuf))) { 27 path = strerror(errno); 28 toys.exitval = 1; 29 } 30 31 xprintf("%s: %s\n", *optargs, path); 32 } 33} 34