kill priority


 
Thread Tools Search this Thread
Top Forums Programming kill priority
# 1  
Old 01-09-2009
kill priority

hello everybody!
i would like to post a question. If i embed in my C code the command kill(9,pid) inside an if command. Is this command(kill) executed in any way. Both if the if is true and false. Does kill have greater priority than the if command.

thanx in advance!
# 2  
Old 01-09-2009
kill is a system call, that is, it runs in kernel mode. What do you mean by 'the priority of if'?

Are you having a problem with the call not working? Are you checking the return code?
# 3  
Old 01-09-2009
Quote:
Originally Posted by jim mcnamara
kill is a system call, that is, it runs in kernel mode. What do you mean by 'the priority of if'?

Are you having a problem with the call not working? Are you checking the return code?
first of all, i would like to thank u for your interest to answer another question of mine!
i appriciate that.
in my code i have a kill command (which send a signal to a process) which is inside an if and when the if is true i want the kill to be executed. what i am asking is: the kill command is executed always despite the result of if condition?
# 4  
Old 01-09-2009
That should not be a behaviour of a (C) program. It should be helpful if you post a snippet of your code within code brackets.

Regards

Last edited by Franklin52; 01-09-2009 at 05:22 PM..
# 5  
Old 01-09-2009
Quote:
Originally Posted by Franklin52
That should not be a behaviour of a (C) program. It should be helpful if you post a snippet of your code within code brackets.

Regards
the snippet of code is posted below!!!any help would be apriciated!!!Smilie

....
Code:
pid = fork();

errno=0;    
    if(pid == 0) //Target Program-Child Process
     {
            dup2(fd2,STDOUT_FILENO);
            dup2(fd2,STDERR_FILENO);
            close(fd2);close(fd1);

               execl(argv[2],argv[3],argv[4],NULL);
//--------------------------------------------pipe -->return here only in the case of execve failure
        close(mypipe[0]);
        write(mypipe[1],strerror(errno),(strlen(strerror(errno))+1));    
//-------------------------------------------end of pipe-----
          exit(EXIT_FAILURE);

         }

    else if (pid>0)//Fault Injector Process-Parent Process
    {
    sprintf(proc_status,"/proc/%d/status",pid);
    timer(0.100);
    f12=fopen(proc_status,"r");fseek(f12,20,SEEK_SET);str=fgetc(f12);
    if(str!='Z'){shoot++;kill(pid,9);}

    
     waitpid(pid,&status,0);//wait for child to finish or interrupt
....
void timer(float cycle)//timer in microsec precision
{
    float count=0.0;
    int loop=1;
while(loop)
{
    usleep(1000);
    count+=0.001;
    if(count>=cycle)
    {loop=0;}
}
}


Last edited by Franklin52; 01-10-2009 at 04:47 AM.. Reason: adding code tags
# 6  
Old 01-10-2009
Looking at this code
Code:
 f12=fopen(proc_status,"r");fseek(f12,20,SEEK_SET);str=fgetc(f12);
    if(str!='Z'){shoot++;kill(pid,9);}

I assume that your problem is that the SIGKILL is being triggered irrespective of whether the character at offset 20 is "Z' or not.

Is 'str' declared as a char or an int?

Also note that if fopen(), fseek() or fgetc() fail the if statement will still be executed with str probably set to some unknown/random value and hence SIGKILL will be triggered. You need to add error checking to avoid this scenario.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Kill an specific process ID using the KILL and GREP commands

Good afternoon I need to KILL a process in a single command sentence, for example: kill -9 `ps -aef | grep 'CAL255.4ge' | grep -v grep | awk '{print $2}'` That sentence Kills the process ID corresponding to the program CAL255.4ge. However it is possible that the same program... (6 Replies)
Discussion started by: enriquegm82
6 Replies

2. Red Hat

The priority of the log

Hi, I can't find the priority in my logs, which under the catalogue of /var/log/lmessages. For example, if the log below occur on my machine, there is no <30>. What should I do if I want to see <30> . <30>Oct 9 22:33:20 hlfedora auditd: The audit daemon is exiting. (0 Replies)
Discussion started by: zhaoyy
0 Replies

3. Red Hat

DNS priority

Hi All, Is this correct on DNS searching? (1st priority) /etc/hosts (2nd p.) /etc/resolv.conf Are there more things that I didn't know? Thank you for any comments you may add. (5 Replies)
Discussion started by: itik
5 Replies

4. AIX

priority for process

hi how to change the priority of a process for eg.if a,b,c these there process are running and if i have to give the b process as high priority and high severe level what should i do (3 Replies)
Discussion started by: senmak
3 Replies

5. Linux

Kill a process without using kill command

I want to Kill a process without using kill command as i don't have privileges to kill the process. I know the pid and i am using Linux 2.6.9 OS. (6 Replies)
Discussion started by: sudhamacs
6 Replies

6. Shell Programming and Scripting

Kill a process without using kill command

Sorry, posted the question in other forum. (0 Replies)
Discussion started by: sudhamacs
0 Replies

7. Shell Programming and Scripting

Please Help me with this ..High Priority!

Hi, I am a nw bie to Schell Scripting, i have a same king of requirement as posted above. my input file is also a log file as below..... 28.05.2008 07:02:56,105 INFO Validation request recieved 28.05.2008 07:03:57,856 INFO 0:01:13.998 Response sent with: <?xml version="1.0"... (0 Replies)
Discussion started by: balaji_gopal
0 Replies

8. Programming

kill(0,-9) don't kill the process

Hi all i have simple c program , when i wish to kill the app im using kill(0,-9) , but it seams this command don't do any thing and the program. just ignore it . what im doing wrong here ? im using HP-UX ia64 Thanks (9 Replies)
Discussion started by: umen
9 Replies

9. UNIX for Advanced & Expert Users

When kill doesnt work, how to kill a process ?

Hi All, I am unable to kill a process using kill command. I am using HP-UX system. I have tried with kill -9 and i have root privilages. How can i terminate this daemon ? ? ? Regards, Vijay Hegde (3 Replies)
Discussion started by: VijayHegde
3 Replies

10. UNIX for Advanced & Expert Users

Increasing priority of a process

Hi! Experts, Is there anyway to incerase the priority of a process which is already started and running??.. I think nice can used for increase priority when we start the process.. But donno how to do when its already running.. Any help would be apreciated.. Jyoti (2 Replies)
Discussion started by: jyotipg
2 Replies
Login or Register to Ask a Question