-
-
Save tatsuru/5538693 to your computer and use it in GitHub Desktop.
chdir(2) and symbolic link
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tatsuru@jami$ ls -l /proc/20949/cwd ~ | |
lrwxrwxrwx 1 tatsuru tatsuru 0 5月 8 15:48 /proc/20949/cwd -> /tmp/chdir/hoge/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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