Thread: Mistery
View Single Post

   
  #3 (permalink)  
Old 02-20-2008, 06:51 AM
Lew Pitcher
 
Posts: n/a
Default Re: Mistery

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

guruteck@gmail.com wrote:
> Hi all
> I have got a doubt in Softlinks.I normally use program /bin/pidof to
> know the process id of a process.But I recently noticed it is a soft
> link to killall5.But when I use killall5 it kills all processes
> instead of find the process id.
> Why this behave like this ??,as both the programs are same .


A program can easily check to find out what name it is run under, and change
it's behaviour accordingly.

int main(int argc, char *argv[])
{
if (argc > 0)
{
if (strcmp(argv[0],"hi") == 0)
printf("Hello, world\n");
else if (strcmp(argv[0],"bye") == 0)
printf("Goodbye, cruel world\n");
else
printf("Whatchu lookn at, Willis?\n");
return 0;
}
else return 1;
}

The above will do different things, if it is run as 'hi' or 'bye' or a.out


- --
Lew Pitcher
IT Specialist, Enterprise Data Systems,
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed are my own, not my employers')
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)

iD8DBQFCMZgvagVFX4UWr64RAqaAAJ4xf1fqQubDSsEW3L8bg1 rilr5eEACfa+qH
oYjR1/XCPqwnuV491Aio+Gc=
=cTGU
-----END PGP SIGNATURE-----
Reply With Quote