diff options
author | John Beppu | 1999-12-09 22:10:18 +0000 |
---|---|---|
committer | John Beppu | 1999-12-09 22:10:18 +0000 |
commit | f95ca97d1bb94307ee0b8ed95d329dc9d6ccec85 (patch) | |
tree | c494de94d27e7d8dc8fdd43b1ca8fe6710e15eda /utility.c | |
parent | 395b216a2eb70ea2796556c06be01261de993687 (diff) | |
download | busybox-f95ca97d1bb94307ee0b8ed95d329dc9d6ccec85.zip busybox-f95ca97d1bb94307ee0b8ed95d329dc9d6ccec85.tar.gz |
findInitPid() has been implemented and it seems to work.
reboot has been changed to take advantage of findInitPid();
Diffstat (limited to 'utility.c')
-rw-r--r-- | utility.c | 43 |
1 files changed, 34 insertions, 9 deletions
@@ -1068,14 +1068,39 @@ extern long getNum (const char *cp) } #endif +#if 1 +/* findInitPid() + * + * This finds the pid of init (which is not always 1). + * Currently, it's implemented by rummaging through the proc filesystem. + * + * [return] + * 0 failure + * pid when init's pid is found. + */ +extern pid_t +findInitPid() +{ + pid_t init_pid; + char filename[256]; + char buffer[256]; + + /* no need to opendir ;) */ + for (init_pid = 1; init_pid < 65536; init_pid++) { + FILE *status; + + sprintf(filename, "/proc/%d/status", init_pid); + status = fopen(filename, "r"); + if (!status) { continue; } + fgets(buffer, 256, status); + fclose(status); + + if ( (strcmp(&buffer[6], "init\n") == 0)) { + return init_pid; + } + } + return 0; +} +#endif /* END CODE */ - - - - - - - - - |