// CreateProcess launches a new process within the computeSystem.
326887
func (computeSystem *System) CreateProcess(c interface{}) (_ *Process, err error) {
	computeSystem.handleLock.RLock()
	defer computeSystem.handleLock.RUnlock()

	operation := "hcsshim::ComputeSystem::CreateProcess"
	computeSystem.logOperationBegin(operation)
	defer func() { computeSystem.logOperationEnd(operation, err) }()

	var (
		processInfo   hcsProcessInformation
		processHandle hcsProcess
		resultp       *uint16
	)

	if computeSystem.handle == 0 {
		return nil, makeSystemError(computeSystem, "CreateProcess", "", ErrAlreadyClosed, nil)
	}

	configurationb, err := json.Marshal(c)
	if err != nil {
		return nil, makeSystemError(computeSystem, "CreateProcess", "", err, nil)
	}

	configuration := string(configurationb)

	logrus.WithFields(computeSystem.logctx).
		WithField(logfields.JSON, configuration).
		Debug("HCS ComputeSystem Process Document")

	syscallWatcher(computeSystem.logctx, func() {
		err = hcsCreateProcess(computeSystem.handle, configuration, &processInfo, &processHandle, &resultp)
	})
	events := processHcsResult(resultp)
	if err != nil {
		return nil, makeSystemError(computeSystem, "CreateProcess", configuration, err, events)
	}

	logrus.WithFields(computeSystem.logctx).
		WithField(logfields.ProcessID, processInfo.ProcessId).
		Debug("HCS ComputeSystem CreateProcess PID")

	process := newProcess(processHandle, int(processInfo.ProcessId), computeSystem)
	defer func() {
		if err != nil {
			process.Close()
		}
	}()
	pipes, err := makeOpenFiles([]syscall.Handle{processInfo.StdInput, processInfo.StdOutput, processInfo.StdError})
	if err != nil {
		return nil, makeSystemError(computeSystem, "CreateProcess", "", err, nil)
	}
	process.stdin = pipes[0]
	process.stdout = pipes[1]
	process.stderr = pipes[2]
	if err = process.registerCallback(); err != nil {
		return nil, makeSystemError(computeSystem, "CreateProcess", "", err, nil)
	}
	go process.waitBackground()

	return process, nil
}
195301
func (p *Init) Create(ctx context.Context, r *CreateConfig) error {
	var (
		err     error
		socket  *runc.Socket
		pio     *processIO
		pidFile = newPidFile(p.Bundle)
	)
	if r.Terminal {
		if socket, err = runc.NewTempConsoleSocket(); err != nil {
			return errors.Wrap(err, "failed to create OCI runtime console socket")
		}
		defer socket.Close()
	} else {
		if pio, err = createIO(ctx, p.id, p.IoUID, p.IoGID, p.stdio); err != nil {
			return errors.Wrap(err, "failed to create init process I/O")
		}
		p.io = pio
	}
	if r.Checkpoint != "" {
		return p.createCheckpointedState(r, pidFile)
	}
	opts := &runc.CreateOpts{
		PidFile:      pidFile.Path(),
		NoPivot:      p.NoPivotRoot,
		NoNewKeyring: p.NoNewKeyring,
	}
	if p.io != nil {
		opts.IO = p.io.IO()
	}
	if socket != nil {
		opts.ConsoleSocket = socket
	}
	if err := p.runtime.Create(ctx, r.ID, r.Bundle, opts); err != nil {
		return p.runtimeError(err, "OCI runtime create failed")
	}
	if r.Stdin != "" {
		if err := p.openStdin(r.Stdin); err != nil {
			return err
		}
	}
	ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
	defer cancel()
	if socket != nil {
		console, err := socket.ReceiveMaster()
		if err != nil {
			return errors.Wrap(err, "failed to retrieve console master")
		}
		console, err = p.Platform.CopyConsole(ctx, console, r.Stdin, r.Stdout, r.Stderr, &p.wg)
		if err != nil {
			return errors.Wrap(err, "failed to start console copy")
		}
		p.console = console
	} else {
		if err := pio.Copy(ctx, &p.wg); err != nil {
			return errors.Wrap(err, "failed to start io pipe copy")
		}
	}
	pid, err := pidFile.Read()
	if err != nil {
		return errors.Wrap(err, "failed to retrieve OCI runtime container pid")
	}
	p.pid = pid
	return nil
}
1098254
func setProcess(s *containerdoci.Spec) {
	if s.Process == nil {
		s.Process = &specs.Process{}
	}
}
194677
func (f ProcessorFunc) Process(g *gif.GIF, params imageserver.Params) (*gif.GIF, error) {
	return f(g, params)
}
1192292
func (c *FakeWorkflows) Create(workflow *v1alpha1.Workflow) (result *v1alpha1.Workflow, err error) {
	obj, err := c.Fake.
		Invokes(testing.NewCreateAction(workflowsResource, c.ns, workflow), &v1alpha1.Workflow{})

	if obj == nil {
		return nil, err
	}
	return obj.(*v1alpha1.Workflow), err
}
13330
func (s *ServerMethods) Create(name string, args ...CmdArg) (*CreatedServer, error) {
	r := &CreatedServer{}
	args = append(args, NewArg("virtualserver_name", name))
	if _, err := s.ExecCmd(NewCmd("servercreate").WithArgs(args...).WithResponse(r)); err != nil {
		return nil, err
	}

	return r, nil
}
1341700
func Process() ([]Nps, error) {
	var npsArr []Nps

	pid, err := process.Pids()

	if err != nil {
		return npsArr, err
	}

	for i := 0; i < len(pid); i++ {
		nps, err := process.NewProcess(pid[i])
		if err != nil {
			return npsArr, err
		}
		names, err := nps.Name()
		if err != nil {
			return npsArr, err
		}

		np := Nps{
			pid[i],
			names,
		}

		npsArr = append(npsArr, np)
	}

	return npsArr, err
}
675291
func startProcess(
	path string,
	args []string,
	env []string,
	pipeW *os.File) (err error) {
	cmd := exec.Command(path)
	cmd.Args = append(cmd.Args, args...)
	cmd.Env = append(cmd.Env, env...)
	cmd.ExtraFiles = []*os.File{pipeW}

	// Change working directories so that we don't prevent unmounting of the
	// volume of our current working directory.
	cmd.Dir = "/"

	// Call setsid after forking in order to avoid being killed when the user
	// logs out.
	cmd.SysProcAttr = &syscall.SysProcAttr{
		Setsid: true,
	}

	// Send along the write end of the pipe.
	cmd.Env = append(cmd.Env, fmt.Sprintf("%s=3", envVar))

	// Start. Clean up in the background, ignoring errors.
	err = cmd.Start()
	go cmd.Wait()

	return
}
781620
func (client *Client) UpdateProcess(process Process) (Process, Warnings, error) {
	body, err := json.Marshal(Process{
		Command:                      process.Command,
		HealthCheckType:              process.HealthCheckType,
		HealthCheckEndpoint:          process.HealthCheckEndpoint,
		HealthCheckTimeout:           process.HealthCheckTimeout,
		HealthCheckInvocationTimeout: process.HealthCheckInvocationTimeout,
	})
	if err != nil {
		return Process{}, nil, err
	}

	request, err := client.newHTTPRequest(requestOptions{
		RequestName: internal.PatchProcessRequest,
		Body:        bytes.NewReader(body),
		URIParams:   internal.Params{"process_guid": process.GUID},
	})
	if err != nil {
		return Process{}, nil, err
	}

	var responseProcess Process
	response := cloudcontroller.Response{
		DecodeJSONResponseInto: &responseProcess,
	}
	err = client.connection.Make(request, &response)
	return responseProcess, response.Warnings, err
}
917654
func (prc ListProcessor) Process(nim image.Image, params imageserver.Params) (image.Image, error) {
	for _, p := range prc {
		var err error
		nim, err = p.Process(nim, params)
		if err != nil {
			return nil, err
		}
	}
	return nim, nil
}
1141531
func (s *Service) DeleteProcess(ctx context.Context, r *shimapi.DeleteProcessRequest) (*shimapi.DeleteResponse, error) {
	if r.ID == s.id {
		return nil, status.Errorf(codes.InvalidArgument, "cannot delete init process with DeleteProcess")
	}
	p, err := s.getExecProcess(r.ID)
	if err != nil {
		return nil, err
	}
	if err := p.Delete(ctx); err != nil {
		return nil, err
	}
	s.mu.Lock()
	delete(s.processes, r.ID)
	s.mu.Unlock()
	return &shimapi.DeleteResponse{
		ExitStatus: uint32(p.ExitStatus()),
		ExitedAt:   p.ExitedAt(),
		Pid:        uint32(p.Pid()),
	}, nil
}
669775
func (c *baseClient) WrapProcess(
	fn func(oldProcess func(cmd Cmder) error) func(cmd Cmder) error,
) {
	c.process = fn(c.process)
}
703434
func (p *Process) waitOnProcess() (*os.ProcessState, error) {
	if p.command == nil || p.command.Process == nil {
		return &os.ProcessState{}, nil
	}

	return p.command.Process.Wait()
}
272268
func (launcher *Launcher) setProcess(proc *os.Process) {
	launcher.Mutex.Lock()
	launcher.process = proc
	launcher.Mutex.Unlock()
}
581658
func (t *Tray) Create() (err error) {
	if err = t.isActionable(); err != nil {
		return
	}
	var e = Event{Name: EventNameTrayCmdCreate, TargetID: t.id, TrayOptions: t.o}
	_, err = synchronousEvent(t.c, t, t.w, e, EventNameTrayEventCreated)
	return
}
617926
func NewProcessor(from io.Reader) (Processor, error) {
	proc := newMemoryProcessor()
	return proc, proc.fastForward(from)
}
1198740
func (d *Deployer) CreateProject(ctx context.Context) (string, error) {
	s, err := cloudresourcemanager.New(d.Client)
	if err != nil {
		return "", err
	}
	// Allow for a few retries, when we generated an already taken project ID
	creationTimeout := time.Now().Add(time.Minute)
	var projectID, projectName string
	for {
		if d.Conf.Project != "" {
			projectID = d.Conf.Project
			projectName = projectID
		} else {
			projectID = genRandomProjectID()
			projectName = strings.Replace(projectID, "camlistore-launcher-", "Camlistore ", 1)
		}
		project := cloudresourcemanager.Project{
			Name:      projectName,
			ProjectId: projectID,
		}
		if time.Now().After(creationTimeout) {
			return "", errors.New("timeout while trying to create project")
		}
		d.Printf("Trying to create project %v", projectID)
		op, err := cloudresourcemanager.NewProjectsService(s).Create(&project).Do()
		if err != nil {
			gerr, ok := err.(*googleapi.Error)
			if !ok {
				return "", fmt.Errorf("could not create project: %v", err)
			}
			if gerr.Code != 409 {
				return "", fmt.Errorf("could not create project: %v", gerr.Message)
			}
			// it's ok using time.Sleep, and no backoff, as the
			// timeout is pretty short, and we only retry on a 409.
			time.Sleep(time.Second)
			// retry if project ID already exists.
			d.Printf("Project %v already exists, will retry with a new project ID", project.ProjectId)
			continue
		}

		// as per
		// https://cloud.google.com/resource-manager/reference/rest/v1/projects/create
		// recommendation
		timeout := time.Now().Add(30 * time.Second)
		backoff := time.Second
		startPolling := 5 * time.Second
		time.Sleep(startPolling)
		for {
			if time.Now().After(timeout) {
				return "", fmt.Errorf("timeout while trying to check project creation")
			}
			if !op.Done {
				// it's ok to just sleep, as our timeout is pretty short.
				time.Sleep(backoff)
				backoff *= 2
				op, err = cloudresourcemanager.NewOperationsService(s).Get(op.Name).Do()
				if err != nil {
					return "", fmt.Errorf("could not check project creation status: %v", err)
				}
				continue
			}
			if op.Error != nil {
				// TODO(mpl): ghetto logging for now. detect at least the quota errors.
				var details string
				for _, v := range op.Error.Details {
					details += string(v)
				}
				return "", fmt.Errorf("could not create project: %v, %v", op.Error.Message, details)
			}
			break
		}
		break
	}
	d.Printf("Success creating project %v", projectID)
	return projectID, nil
}