Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shell Process ID

Status
Not open for further replies.

ronnyjljr

IS-IT--Management
Nov 23, 2003
249
US
How do I get the value of the process id of the shell that I am current in? "$$" works from the command line, but I need a C command if at all possble. I have tried setting it with environment variables but have had no success.

Thanks,
Ron

typedef map<GiantX,gold, less<std::shortestpathtogold> > AwesomeMap;
 
Code:
#include <sys/types.h>
#include <unistd.h>

int main()
{
  pid_t pid = getpid();
  return 0;
}
 
That just gets the PID of the program I am running. I want to get the PID of the actually shell where I typed the command. Typing '$$' at the command line will give me the number but I still can not find a C command,

Thanks,
Ron

typedef map<GiantX,gold, less<std::shortestpathtogold> > AwesomeMap;
 
Then try [tt]getppid[/tt] (get parent process id).

That will get the process that started the program, which will be the shell, assuming you ran the command from the command line.
 
That didn't work, seemed like a good idea though.

Thanks,
Ron

typedef map<GiantX,gold, less<std::shortestpathtogold> > AwesomeMap;
 
> That didn't work, seemed like a good idea though.
Time to post what you actually tried then, along with say error messages (or other output which you deemed to be incorrect), along with what you expected to happen.

PS.
Don't forget the [code][/code] tags.

--
 
Actually,

The getppid() did work for me. I was running the command through make and that is why the incorrect pid was given. Running the command on its own produced the correct Shell pid.

Thanks,
Ron

typedef map<GiantX,gold, less<std::shortestpathtogold> > AwesomeMap;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top