Home » C programs

Solution of Warning implicit declaration of function 'getpid' in C



Here, we are going to learn how to fix the issue of “Warning implicit declaration of function 'getpid'” while compiling C program?
Submitted by IncludeHelp, on March 08, 2018

What is implicit declaration of function 'getpid' Warning?

Warning implicit declaration of function 'getpid' - While getting Process Id, this is the common warning which occurs.

Consider the following code snippet

#include <stdio.h>
 
int main()
{
    printf("Process Id is: %ld\n",getpid());
    return 0;
}

See the warning after compiling the program

    warning: implicit declaration of function 'getpid'

This is the same problem, for which you are looking?

Then, what's the solution?

getpid() - is used to get process id of the current process, and it is declared in <unistd.h> header file.

The warning occurs, if you do not include this header file, to fix the warning include <unistd.h> header file in the program.

[SOLVED] Consider the code snippet

#include <stdio.h>
#include <unistd.h>
 
int main()
{
    printf("Process Id is: %ld\n",getpid());
    return 0;
}

Output

    Process Id is: 98

Related program...

C program to get Process Id and Parent Process Id in Linux.






Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.



Comments and Discussions





© https://www.includehelp.com (2015-2018), Some rights reserved.




Like other websites, this site uses cookies to deliver relevant ads based on your interest, by using our website, you acknowledge that you have read our privacy policy.
Close