[prog] check if script parent process is "init"
johnc+linuxchix at kirriwa.net
Wed Apr 21 18:33:46 EST 2004
On Wed, Apr 21, 2004 at 08:35:35AM +0200, dominik schramm wrote:
> $ cat caller.sh
> . callee
> $ cat callee
> # contains bash specific syntax
> My thought was that this couldn't work.
It'll work fine, because the kernel uses the first line of the script
(the part after "#!") to find the handler. caller.sh can only contain
sh commands because it's being run by /bin/sh, but callee is being run
by /bin/bash so it can include anything that bash understands.
The kernel reads the first line; if it starts with "#!", it gets the
name of the program that follows and runs that program, with up to (I
think) two arguments plus the name of the file. It's simple enough to
write your own handler:
[johnc at dropbear ~/tmp]$ cat echo.c
int main(int argc, char *argv)
if (argc < 1)
f = fopen(argv, "r");
if (f == NULL)
printf("Cannot open %s: %s\n", argv, sys_errlist[errno]);
while (fgets(line, sizeof(line), f) != NULL)
if (line != '#')
[johnc at dropbear ~/tmp]$ gcc -W -Wall -std=c99 -Wno-unused-parameter -o echo echo.c
[johnc at dropbear ~/tmp]$ cat echo.sh
[johnc at dropbear ~/tmp]$ ./echo.sh
> ... In the mean time, suggestions are welcomed as to what to do to the
> buffoon who wrote the current Virus du Jour.
Do you mean the larger part that was written in Redmond, or the minority
part that someone else contribbed? -- Anthony de Boer
More information about the Programming