How to know your current shell from C code

Chuck.Phillips Chuck.Phillips at FtCollins.NCR.COM
Thu Sep 13 03:12:02 AEST 1990


>>>>> On 11 Sep 90 16:44:36 GMT, mikel at cadence.cadence.com said:
mikel> Recently I had a UNIX question.  I have a c program and I want to
mikel> know which shell(sh,csh,ksh) is my parent.  Is there any way to do
mikel> this?  Environment variable is not acceptable.

There is always the kludge of calling getppid() for your parent's process
ID, then examining the output of "ps" (given appropriate arguments) to find
out what fired off your program.  Note: If your C program has a shell
script wrapper, _that_ is what you'll find, not the shell the user used.  I
_assume_ this is what you care about and not the user's shell, otherwise
the SHELL environment variable probably would be a better approach.

Even less portably, your program can run as SUID root or SGID kmem and wade
through /dev/(k)mem for information.

	Have fun,

Chuck Phillips  MS440
NCR Microelectronics 			Chuck.Phillips%FtCollins.NCR.com
2001 Danfield Ct.
Ft. Collins, CO.  80525   		uunet!ncrlnk!ncr-mpd!bach!chuckp
--
Chuck Phillips  MS440
NCR Microelectronics 			Chuck.Phillips%FtCollins.NCR.com
2001 Danfield Ct.
Ft. Collins, CO.  80525   		uunet!ncrlnk!ncr-mpd!bach!chuckp



More information about the Comp.unix.internals mailing list