Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1060315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:18:33+00:00 2026-05-16T18:18:33+00:00

I am trying to implement EINVAL, EPERM, ESRCH in my program. ERRORS EINVAL An

  • 0

I am trying to implement EINVAL, EPERM, ESRCH in my program.

ERRORS
EINVAL An invalid signal
was specified.
EPERM The process
does not have permission to send the
signal to any of the target processes.
ESRCH The pid or process group does
not exist.

Here’s my source code :

#include <stdio.h>
#include <sys/types.h>
#include <signal.h>
#include <unistd.h>

int main(void)
{

 int errno, pid;

 puts("Enter a process id : ");
 scanf("%d", &pid);

    errno = kill(pid, 1);

 if(errno == -1)
 {
  printf("Cannot find or kill the specified process\n");

 }


 switch(errno)
 {
  case EINVAL:
   printf("An invalid signal was specified.\n");
   break;

  case EPERM:
   printf("The process does not have permission to send the signal to any of the target processes.\n");
   break;

  case ESRCH:
   printf("The  pid or process group does not exist.");
   break;
 }

}

And when I compile the program I get the following errors.

unipro@ubuguest:/SoftDev/ADSD/Module
1/Unit 1/Pratice/C/C_adv/unix$ cc
killApp.c -o killApp
killApp.c: In
function ‘main’:
killApp.c:29:
error: ‘EINVAL’ undeclared (first use
in this function)
killApp.c:29:
error: (Each undeclared identifier is
reported only once
killApp.c:29:
error: for each function it appears
in.)
killApp.c:33: error: ‘EPERM’
undeclared (first use in this
function)
killApp.c:37: error:
‘ESRCH’ undeclared (first use in this
function)
unipro@ubuguest:/SoftDev/ADSD/Module
1/Unit 1/Pratice/C/C_adv/unix$

So where are EINVAL, EPERM, ESRCH defined? Do I need to define any additional header file? Or I am implementing it in a wrong way?

Updated Code [working code] :

#include <stdio.h>
#include <sys/types.h>
#include <signal.h>
#include <unistd.h>
#include <errno.h>

int main(void)
{

    int status, pid;

    puts("Enter a process id : ");
    scanf("%d", &pid);

    status = kill(pid, 1);



    switch(errno)
    {
        case EINVAL:
            printf("An invalid signal was specified.\n");
            break;

        case EPERM:
            printf("The process does not have permission to send the signal to any of the target processes.\n");
            break;

        case ESRCH:
            printf("The  pid or process group does not exist.");
            break;
    }

}

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T18:18:34+00:00Added an answer on May 16, 2026 at 6:18 pm

    What you’re trying to do won’t work, first you should #include <errno.h> (as that’s where errno is defined, as are the error codes).
    Second, don’t call your local return value variable errno (as that exists and is where the error code will be).

    eg.

    #include <errno.h>
    /* ... */
    
    int rc;
    /* ... */
    
    rc = kill(pid, SIGHUP);
    if (rc != 0)
    {
        switch (errno) {...}
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to implement 3-layer (not: tier, I just want to separate my project logically,
Trying to implement NSCopying for the first time, and I have a question about
I have this weird kind of error. I am trying implement basic Euclidean algorithm
Trying to implement what I thought was a simple concept. I have a user
I'm trying implement a bracket in my program (using C#/.NET MVC) and I am
I'm trying implement my project in Apache Struts 2 but I'm not very familiar
Im trying to implement pagination using multiple searching criteria. Supposed I Have student table.
am trying to implement fluent nhibernate in MVC project...there were no build errors... but
Trying to implement sticky footer but its not working as planned. It throws it
Trying to implement the following behavior on an iPad. I have a map-centric application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.