Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os: document that FindProcess is a no-op on Unix #14146

Closed
gaurav36 opened this issue Jan 29, 2016 · 12 comments
Closed

os: document that FindProcess is a no-op on Unix #14146

gaurav36 opened this issue Jan 29, 2016 · 12 comments

Comments

@gaurav36
Copy link

@gaurav36 gaurav36 commented Jan 29, 2016

Hi Team,

I just find one bug in golang.

bug is this when you execute os.FindProcess (pid) command two time then its giving wrong information. ie. if process is not exist then executing os.FindProcess for that process pid again is not giving proper error, its giving nil error.

for eg execute below code:

package main                                                                       

import (                                                                           
        "fmt"                                                                      
        "os"                                                                       
)                                                                                  

func main() {                                                                      
        pid := 12345678                                                            

        if _, err := os.FindProcess(pid); err != nil {                             
                fmt.Printf("process with pid %d is not exist\n", pid)              
        }                                                                          
        if _, e := os.FindProcess(pid); e == nil {                                                                    
                fmt.Printf("process with pid %d exist\n", pid)                     
        }                                                                          
}  

so expected behaviour of this code is it should not print anything. but its printing that pid is exist. even process is not running.

Any help regarding this. i am using this in one of the my application.

Thanks, in advance :)

@dominikh
Copy link
Member

@dominikh dominikh commented Jan 29, 2016

Your issue is unrelated to running os.FindProcess multiple times. Running it once suffices. And the underlying cause of your problem is that on Unix-systems, os.FindProcess isn't actually doing any finding. All it does is return an *os.Process with the pid set to the argument. As such, the error will always be nil. If you ran your code on Windows, it would return an error.

@gaurav36
Copy link
Author

@gaurav36 gaurav36 commented Jan 29, 2016

@dominikh i don't have window. wondering why golang have limited this error code to only window.

@gaurav36
Copy link
Author

@gaurav36 gaurav36 commented Jan 29, 2016

anyway its seems to be a issue because of giving wrong error information !!!!

@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Jan 29, 2016

This is documented. Working as intended.

@bradfitz bradfitz closed this Jan 29, 2016
@gaurav36
Copy link
Author

@gaurav36 gaurav36 commented Jan 29, 2016

@bradfitz Could you please provide me the link of that document. What do you mean by "working as intended" ???

imo before closing the issue you should have provided me the link of document.

do you mean to say os.FindProcess giving correct error message in all system. ?

If that problem have fixed then i want to know where, in which version it have fixed other wise there is no point of closing known issue bug. known issue bug should always open.

@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Jan 29, 2016

Oh, it's only documented internally, not in the public docs. Okay, we can fix the docs.

@bradfitz bradfitz reopened this Jan 29, 2016
@bradfitz bradfitz changed the title Golang os.FindProcess is giving wrong error information os: document that FindProcess is a no-op on Unix Jan 29, 2016
@bradfitz bradfitz added this to the Unplanned milestone Jan 29, 2016
@gaurav36
Copy link
Author

@gaurav36 gaurav36 commented Jan 29, 2016

@bradfitz Thank you for opening the issue :)

Now you have changed the subject line of this bug " Golang os.FindProcess is giving wrong error information to os: document that FindProcess is a no-op on Unix "

I am using latest version of Golang and didn't saw that error message problem have solved. If error message problem had not solved yet then you should have raised separate documentation issue. Mixing of both documentation and code change issue really confusing.

Any way closing of issue should only happen when you provide following things:

  1. It should be not a bug
  2. It have patch in current release or whatever release and its no longer reproducible
  3. this issue is same copy of another issue which had raised by another community member.

If it have not solved and if i get time then i might think about to solve this issue and send a patch.

Thank you :)

@dominikh
Copy link
Member

@dominikh dominikh commented Jan 29, 2016

There is no code issue, only a documentation issue. os.FindProcess does not check the validity of a PID on most systems. That needs to be documented. Its behaviour won't change.

@gaurav36
Copy link
Author

@gaurav36 gaurav36 commented Jan 29, 2016

@dominikh Thanks for clearing this. That make sense. Now i will follow some other method to check whether given pid process exist in unix system or not instead of using os.FindProcess.

@gopherbot
Copy link

@gopherbot gopherbot commented Jan 29, 2016

CL https://golang.org/cl/19093 mentions this issue.

@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Jan 29, 2016

You can send it signal 0 to test it, assuming you have permission.

@gaurav36
Copy link
Author

@gaurav36 gaurav36 commented Jan 29, 2016

@bradfitz
yeah, i am now doing it with kill 0 signal.
Thank you :)

@gopherbot gopherbot closed this in af15bee Jan 29, 2016
@golang golang locked and limited conversation to collaborators Feb 3, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.