Jiri Simsa | d7616c9 | 2015-03-24 23:44:30 -0700 | [diff] [blame] | 1 | // 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 Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 5 | package exec |
| 6 | |
| 7 | import ( |
| 8 | "log" |
| 9 | "os/exec" |
| 10 | "time" |
| 11 | ) |
| 12 | |
| 13 | func ExampleChildHandle() { |
Jiri Simsa | 84059da | 2014-06-02 17:22:05 -0700 | [diff] [blame] | 14 | ch, _ := GetChildHandle() |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 15 | // 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 | |
| 22 | func ExampleParentHandle() { |
| 23 | cmd := exec.Command("/bin/hostname") |
Jiri Simsa | c199bc1 | 2014-05-30 12:52:24 -0700 | [diff] [blame] | 24 | ph := NewParentHandle(cmd, SecretOpt("secret")) |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 25 | |
| 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 | } |