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

  • SEARCH
  • Home
  • 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 8829415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:49:49+00:00 2026-06-14T07:49:49+00:00

Kill(pid, 0) seems to not set the error code correctly…as stated in man for

  • 0

Kill(pid, 0) seems to not set the error code correctly…as stated in man for kill

Errors

The kill() function shall fail if:

EINVAL The value of the sig argument is an invalid or unsupported
signal number.
EPERM The process does not have permission to send the
signal to any receiving process.
ESRCH No process or process group can
be found corresponding to that specified by pid. The following
sections are informative.
1

It is returning ENOENT (no such file or directory) and then sometimes it returns EINTR (system call interrupted)…

Here is what I am doing:

kill(g_StatusInstance[i].pid, SIGTERM) == -1 && log_fatal_syscall("kill-sigterm");
kill(g_StatusInstance[i].pid, 0);

log_info_console( "Checking process for errors: %s\n", strerror(errno));

if(errno != ENOENT)
{
   kill(g_StatusInstance[i].pid, SIGKILL) == -1 && log_fatal_syscall("kill-sigkill");
}

Am I doing something wrong?

  • 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-06-14T07:49:50+00:00Added an answer on June 14, 2026 at 7:49 am

    Kill(pid, 0) seems to not set the error code correctly …
    It is returning ENOENT… EINTR

    Here is what I am doing:

    ...
    kill(g_StatusInstance[i].pid, 0);
    log_info_console( "Checking process for errors: %s\n", strerror(errno));
    

    Am I doing something wrong?

    Yes. You are not checking the return value of the kill() system call. kill() does not set errno to any particular value in the successful case.

    Try this:

    if(kill(g_StatusInstance[i].pid, 0) == -1) {
      log_info_console( "Checking process for errors: %s\n", strerror(errno));
    } else {
      log_info_console( "kill returned 0, process still alive\n" );
    }
    

    More generally, you ought to check the return value of every system call or library call, unless it is declared to return void.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is there an equivalent to the function kill() on Windows? int kill(pid_t pid, int
I am on Centos 4 and am using kill(pid, 0) in my C++ program
If I kill the Socket Server process, my Socket client process does not receive
It seems that following code is wrong, as on the first call the code
I have the following situation (pseudocode): function f: pid = fork() if pid ==
for example from bash: kill -9 -PID os.kill(pid, signal.SIGKILL) kill only parent process.
I want to run some application in background and later kill it by pid.
i couldnt make my program sleep() after using kill(pid,SIGTERM) what can i do ?
I have a cleanup process which needs to kill the process whose PID is
I need to kill x window system on mac (I'm linux user, I don't

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.