Skip to content

Instantly share code, notes, and snippets.

@tatsuru
Created May 8, 2013 06:48
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tatsuru/5538693 to your computer and use it in GitHub Desktop.
chdir(2) and symbolic link
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
int main(int argc, char **argv) {
chdir(argv[1]);
pid_t pid = getpid();
printf("%d\n", (int)pid);
fflush(stdout);
sleep(60);
return 0;
}
tatsuru@jami$ ls -l /proc/20949/cwd ~
lrwxrwxrwx 1 tatsuru tatsuru 0 5月 8 15:48 /proc/20949/cwd -> /tmp/chdir/hoge/
tatsuru@jami$ gcc c.c /tmp/chdir
tatsuru@jami$ ls -l /tmp/chdir
合計 16
-rwxr-xr-x 1 tatsuru tatsuru 7439 5月 8 15:46 a.out*
-rw-r--r-- 1 tatsuru tatsuru 212 5月 8 15:45 c.c
lrwxrwxrwx 1 tatsuru tatsuru 4 5月 8 15:41 fuga -> hoge/
drwxr-xr-x 2 tatsuru tatsuru 4096 5月 8 15:41 hoge/
tatsuru@jami$ ./a.out fuga /tmp/chdir
20949
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment