Re: [Debian]:getpid()
Am Sonntag, den 02. April 2000, um 20:17h schrieb Gerhard Engleder:
> Will mich ein wenig mit Linuxprogrammierung befassen und habe schon das
> erste Problem!
>
> #include <iostream.h>
> #include <unistd.h>
>
> int main()
> {
> pid_t pid ;
> pid = getpid() ;
> std::cout << pid ;
> }
>
> Der Compiler meldet das pid_t nichtdefiniert ist, deshalb frage ich
> mich welchen Header außer unistd.h ich noch brauche (habe in der C/C++
> Referenz nichts gefunden außer unistd.h )?
> Wenn ich statt pid_t int nehme funktioniert es schon fast,
> allerdings ist die PID die mein Programm ermittelt immer um 1 höher als
> die die ich mit ps x ermittle, und kill -HUP n funktioniert auch
> nur mit der PID von ps x , also nehme ich an das die PID von meinem
> Programm falsch ist!
wirf' mal einen Blick in die unistd.h:
===cut===
#ifdef __USE_XOPEN
/* The Single Unix specification says that some more types are
available here. */
[...]
# ifndef pid_t
typedef __pid_t pid_t;
# define pid_t pid_t
# endif
#endif /* X/Open */
===cut===
pid_t wird also per default nicht definiert...
__pid_t wird in bits/types.h definiert:
===cut===
typedef int __pid_t; /* Type of process identifications. */
===cut===
pid_t ist also ein normaler int. Das Problem mit der Prozessnummer kann
ich nicht nachvollziehen:
===cut===
#include <iostream>
extern "C"
{
#include <unistd.h>
}
using namespace std;
int main()
{
int pid;
pid = getpid();
cout << "Meine PID ist: " << pid << endl;
pause();
}
===cut===
Ausgabe:
===cut===
michael@flame:[~]$ ./pid
Meine PID ist: 3057
===cut===
"ps u" sagt:
===cut===
[...]
michael 3057 0.0 0.8 1376 520 pts/0 S 13:06 0:00 ./pid
[...]
===cut===
--
Michael LDKnet / LDK/LUG / Unix-AG
*Weitzel* /LinuX --- email: weitzel@ldknet.org
------------------------------------------------
Um sich aus der Liste auszutragen schicken Sie
bitte eine E-Mail an majordomo@jfl.de die im Body
"unsubscribe debian-user-de <deine emailadresse>"
enthaelt.
Bei Problemen bitte eine Mail an: Jan.Otto@jfl.de
------------------------------------------------
Anzahl der eingetragenen Mitglieder: 742
Reply to: