Note that there are some explanatory texts on larger screens.

plurals
  1. POImplementing EINVAL, EPERM, ESRCH in Kill()
    primarykey
    data
    text
    <p>I am trying to implement EINVAL, EPERM, ESRCH in my program.</p> <blockquote> <p>ERRORS<br> EINVAL An invalid signal was specified.<br> 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.</p> </blockquote> <p>Here's my source code :</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;sys/types.h&gt; #include &lt;signal.h&gt; #include &lt;unistd.h&gt; int main(void) { int errno, pid; puts("Enter a process id : "); scanf("%d", &amp;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; } } </code></pre> <p>And when I compile the program I get the following errors.</p> <blockquote> <p>unipro@ubuguest:/SoftDev/ADSD/Module 1/Unit 1/Pratice/C/C_adv/unix$ cc killApp.c -o killApp<br> killApp.c: In function ‘main’:<br> killApp.c:29: error: ‘EINVAL’ undeclared (first use in this function)<br> killApp.c:29: error: (Each undeclared identifier is reported only once<br> killApp.c:29: error: for each function it appears in.)<br> killApp.c:33: error: ‘EPERM’ undeclared (first use in this function)<br> killApp.c:37: error: ‘ESRCH’ undeclared (first use in this function)<br> unipro@ubuguest:/SoftDev/ADSD/Module 1/Unit 1/Pratice/C/C_adv/unix$ <br></p> </blockquote> <p>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?</p> <p><strong>Updated Code [working code] :</strong></p> <pre><code>#include &lt;stdio.h&gt; #include &lt;sys/types.h&gt; #include &lt;signal.h&gt; #include &lt;unistd.h&gt; #include &lt;errno.h&gt; int main(void) { int status, pid; puts("Enter a process id : "); scanf("%d", &amp;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; } } </code></pre> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload