how to get rid of "warning : implicit declaration of function 'getpid' " ?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
how to get rid of "warning : implicit declaration of function 'getpid' " ?
I am new to C .
I compile a C program on a SUNFIRE machine, with gcc 2.95.2 and I get the warning.
My code is :
===================================
#include <stdio.h>;
int main(int arg, char *argv[]){
printf("my PID is %d\n", getpid());
return 0;
}
===================================
and I get :
"warning : implicit declaration of function 'getpid' "
I guess I didn't include some kind of library.
Can some1 help ?
"warning : implicit declaration of function 'getpid' "
error is because getpid() is not declared before its use. This is because you have not included the header files in which it is declared. Here's a snippet of what man getpid has to say :
Code:
SYNOPSIS
#include <sys/types.h>
#include <unistd.h>
pid_t getpid(void);
pid_t getppid(void);
DESCRIPTION
getpid returns the process ID of the current process. (This is often used
by routines that generate unique temporary file names.)
getppid returns the process ID of the parent of the current process.
So inlude those header files and recompile your program.
Hope this helps.
It's different on my UNIX on Sunfire . When I try man fork I get this :
=======================================================================
Fortran Library Routines FORK(3F)
NAME
fork - create a copy of this process
SYNOPSIS
integer*4 function fork()
DESCRIPTION
The fork function creates a copy of the calling process.
The only distinction between the two processes is that the
value returned to one of them, referred to as the 'parent'
process, is the process id of the copy. The copy is usually
referred to as the `child' process. The value returned to
the `child' process is zero.
All logical units open for writing are flushed before the
fork to avoid duplication of the contents of I/O buffers in
the external files.
If the returned value is negative, it indicates an error and
is the negation of the system error code. See perror(3F).
A corresponding exec routine has not been provided because
there is no satisfactory way to retain open logical units
across the exec. However, the usual function of fork/exec
can be performed using system(3F).
FILES
libfui.a
SEE ALSO
fork(2), wait(3F), kill(3F), system(3F), perror(3F)
SunOS 5.8 Last change: 03/02/25
=======================================================================
It's different on my UNIX on Sunfire . When I try man fork I get this :
It's got to be different. What you've posted is the output of man fork while what I said was man getpid, read my post.
Why are you worrying about fork. As far as the error is concerned, its getpid that's causing it. It's not even an error, but a warning, and your program should still execute. On my P.C. I just copied and pasted your code and it ran fine (except for that semi-colon after #include <stdio.h> ;)
Quote:
So dear, what is the neccessary lib to include to get rid of the warning ?
You have all the libraries, its just that the declaration is missing.
As far as getting rid of the warning is concerned, just include the header files sys/types.h and unistd.h and it should work fine.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.