blob: b8157e8120f566e3c0ecb02468563b1d430d29bc [file] [log] [blame]
Jiri Simsad7616c92015-03-24 23:44:30 -07001// Copyright 2015 The Vanadium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
Jiri Simsa5293dcb2014-05-10 09:56:38 -07005package exec
6
7import (
8 "log"
9 "os/exec"
10 "time"
11)
12
13func ExampleChildHandle() {
Jiri Simsa84059da2014-06-02 17:22:05 -070014 ch, _ := GetChildHandle()
Jiri Simsa5293dcb2014-05-10 09:56:38 -070015 // Initalize the app/service, access the secret shared with the
16 // child by its parent
17 _ = ch.Secret
18 ch.SetReady()
19 // Do work
20}
21
22func ExampleParentHandle() {
23 cmd := exec.Command("/bin/hostname")
Jiri Simsac199bc12014-05-30 12:52:24 -070024 ph := NewParentHandle(cmd, SecretOpt("secret"))
Jiri Simsa5293dcb2014-05-10 09:56:38 -070025
26 // Start the child process.
27 if err := ph.Start(); err != nil {
28 log.Printf("failed to start child: %s\n", err)
29 return
30 }
31
32 // Wait for the child to become ready.
33 if err := ph.WaitForReady(time.Second); err != nil {
34 log.Printf("failed to start child: %s\n", err)
35 return
36 }
37
38 // Wait for the child to exit giving it an hour to do it's work.
39 if err := ph.Wait(time.Hour); err != nil {
40 log.Printf("wait or child failed %s\n", err)
41 }
42}