Find the answer to your Linux question:
Results 1 to 7 of 7
Hi, I am using kill(pid,0) using c program to test a process on linux. But there is no process with pid running & another process pid1has same thread id as ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jan 2013
    Posts
    4

    Alternative to kill system call using c program to test only process.


    Hi,

    I am using kill(pid,0) using c program to test a process on linux. But there is no process with pid running & another process pid1has same thread id as pid. Hence kill return success(process exists,but no process with that pid). But I am looking for similar api that checks only process level with similar performance like kill. Can any one please help on this.

    Thanks
    Mrinmoy

  2. #2
    Linux Newbie Syndacate's Avatar
    Join Date
    May 2012
    Location
    Hell..no literally, this state is hell..
    Posts
    192
    Quote Originally Posted by deymrinmoy View Post
    Hi,

    I am using kill(pid,0) using c program to test a process on linux. But there is no process with pid running & another process pid1has same thread id as pid. Hence kill return success(process exists,but no process with that pid). But I am looking for similar api that checks only process level with similar performance like kill. Can any one please help on this.

    Thanks
    Mrinmoy
    Do you know the name of the process where you can use 'pidof' or 'killall' or do you only know it by PID?

    I didn't know kill would go beyond the PID # and target it based on TID :-\. That's news to me.

  3. #3
    Just Joined!
    Join Date
    Jan 2013
    Posts
    4
    Hi,

    I can find out process name . But it will cost additional performance.
    So I want to call by pid.

    Regards,
    Mrinmoy

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Newbie Syndacate's Avatar
    Join Date
    May 2012
    Location
    Hell..no literally, this state is hell..
    Posts
    192
    Quote Originally Posted by deymrinmoy View Post
    Hi,

    I can find out process name . But it will cost additional performance.
    So I want to call by pid.

    Regards,
    Mrinmoy
    Hrm, sorry, out of ideas, this isn't my strong point but never-the-less, I didn't even know PID's would go 'beyond' the process and target based on threads, I've never heard of that behavior, that's kind of news to me.

  6. #5
    Just Joined!
    Join Date
    Jan 2013
    Posts
    4
    Hi All,

    To give more details about the behavior on kill on Linux. We can find any multi-threaded process and call kill 0 for any thread of it. For Linux, kill 0 returns success for that thread. But for other UNIX, kill 0 could not find that thread .

    For example,
    #ps -eaf|grep automount
    root 2480 1 0 Jan02 ? 00:00:11 automount

    #pstack 2480 |grep -i LWP
    Thread 5 (Thread 0x41e37940 (LWP 2481)):
    Thread 4 (Thread 0x41e48940 (LWP 2482)):
    Thread 3 (Thread 0x42849940 (LWP 2485)):
    Thread 2 (Thread 0x412a2940 (LWP 248):
    Thread 1 (Thread 0x2b5ed7783af0 (LWP 2480)):


    On Linux, Kill(0,2485) finds, but for other UNIX it does not find.


    It seems that kill(0,pid) first search pid for process , if process does not exists with that id, then it goes till thread level.

    Please let me know any alternative or I can restrict to test process by pid till process level.

    Many thanks in advance.

    Regards,
    Mrinmoy

  7. #6
    Linux Newbie Syndacate's Avatar
    Join Date
    May 2012
    Location
    Hell..no literally, this state is hell..
    Posts
    192
    Quote Originally Posted by deymrinmoy View Post
    Hi All,

    To give more details about the behavior on kill on Linux. We can find any multi-threaded process and call kill 0 for any thread of it. For Linux, kill 0 returns success for that thread. But for other UNIX, kill 0 could not find that thread .

    For example,
    #ps -eaf|grep automount
    root 2480 1 0 Jan02 ? 00:00:11 automount

    #pstack 2480 |grep -i LWP
    Thread 5 (Thread 0x41e37940 (LWP 2481)):
    Thread 4 (Thread 0x41e48940 (LWP 2482)):
    Thread 3 (Thread 0x42849940 (LWP 2485)):
    Thread 2 (Thread 0x412a2940 (LWP 248):
    Thread 1 (Thread 0x2b5ed7783af0 (LWP 2480)):


    On Linux, Kill(0,2485) finds, but for other UNIX it does not find.


    It seems that kill(0,pid) first search pid for process , if process does not exists with that id, then it goes till thread level.

    Please let me know any alternative or I can restrict to test process by pid till process level.

    Many thanks in advance.

    Regards,
    Mrinmoy
    Hrm, don't know man, I'm not sure if that's proper functionality.

    I've never used true UNIX so I really can't say, but I've never heard of it doing anything lower than the process level, as I stated earlier. You sure it's not failing for some other reason?

  8. #7
    Just Joined!
    Join Date
    Jan 2013
    Posts
    4
    Hi,

    In other UNIX, kill(pid,0) checks properly , it returns success(process exists) if the process with pid exists. It does not go till thread level if process with pid does not exists and returns as process with pid does not exists. Which is proper behavior.

    As I told earlier, on Linux kill(pid,0) checks till thread level if no process with pid exists and it returns success(process exists) if any other process has same thread id as pid.
    Is this a problem on Linux kill? or there is any additional way we can check only for process?

    Regards,
    Mrinmoy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •