Skip to content

SIGCHLD wakes up time.Sleep #268

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

Closed
gopherbot opened this issue Nov 19, 2009 · 4 comments
Closed

SIGCHLD wakes up time.Sleep #268

gopherbot opened this issue Nov 19, 2009 · 4 comments

Comments

@gopherbot
Copy link
Contributor

by gfranxman:

What steps will reproduce the problem?
1. Calling ForkExec
2. Calling time.Sleep

--- example ---
package main

import "fmt"
import "os"
import "time"

func main() {
    fmt.Printf("First 5 sec Sleep\n" ) ;
    time.Sleep(1000* 1000*1000 * 5) ;

    // forkexec seems to break the timer
    pid, err := os.ForkExec("/bin/date", []string{"date"}, os.Environ(),
"", []*os.File{os.Stdin, os.Stdout, os.Stderr});
    fmt.Printf( "pid, err:%d, %d\n" , pid, err ) ;

    fmt.Printf("Second 5 sec Sleep\n" ) ;
    time.Sleep(1000* 1000*1000 * 5) ;

    fmt.Printf("Done\n" ) ;
}
--- /example --


What is the expected output? What do you see instead?

I would expect the example program to output "First 5 sec Sleep" then pause
for 5 seconds, then output "Second 5 sec Sleep" and pause for 5 more
seconds before printing "Done".    The output from the ForkExec'd /bin/date
command should shouw up asynchonously.

What is your $GOOS?  $GOARCH?
GOARCH=amd64
GOOS=linux


Which revision are you sync'ed to?  (hg log -l 1)

$ hg log -l 1
changeset:   4108:d1b75410b793
tag:         tip
user:        Adam Langley <agl@golang.org>
date:        Tue Nov 17 18:21:47 2009 -0800
summary:     crypto/rsa: add PKCS#1 v1.5 signature support.
@rsc
Copy link
Contributor

rsc commented Nov 20, 2009

Comment 1:

The problem is that when the forked /bin/date
exits, Sleep gets a signal and doesn't restart.
It's hard to know what to do here in general--this is
really a question of Unix semantics, not Go semantics--
but I think the solution is to not allow SIGCHLD to interrupt
system calls.

Owner changed to r...@golang.org.

Status changed to Accepted.

@gopherbot
Copy link
Contributor Author

Comment 2 by gfranxman:

Confirmed.    This functions as expected:
--- Example ---
package main
import "fmt"
import "os"
import "time"
import "syscall"
func main() {
    var wstatus syscall.WaitStatus;
    fmt.Printf("First 5 sec Sleep\n" ) ;
    time.Sleep(1000* 1000*1000 * 5) ;
    // wait must be called on the forked proc, otherwise the SIGCHILD interferes with
the subsequent call to time.Sleep
    pid, forkerr := os.ForkExec("/bin/date", []string{"date"}, os.Environ(), "",
[]*os.File{os.Stdin, os.Stdout, os.Stderr});
    _, waiterr := syscall.Wait4(pid, &wstatus, 0, nil);
    fmt.Printf( "pid, forkerr, waiterr:%d, %d, %d\n" , pid, forkerr, waiterr ) ;
    fmt.Printf("Second 5 sec Sleep\n" ) ;
    time.Sleep(1000* 1000*1000 * 5) ;
    fmt.Printf("Done\n" ) ;
}
--- /Example ---
  
Probably should be using the exec.Cmd struct for this type of functionality.

@rsc
Copy link
Contributor

rsc commented Dec 2, 2009

Comment 3:

Labels changed: added packagebug.

@rsc
Copy link
Contributor

rsc commented Feb 9, 2010

Comment 4:

thanks to cw@f00f.org

Status changed to Fixed.

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants