Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

6 Commits

Repository files navigation

Process

A Package to check whether process is already running for Go(golang). process can prevent the process from being duplicated.

Installation

$ go get github.com/zajann/process

Usage

package main
import (
"github.com/zajann/process"
)
funcmain() {
pidFilePath:="./test.pid"running, err:=process.IsRunning(pidFilePath)
iferr!=nil {
panic(err)
}
ifrunning {
// Process is already running. Process exit.
}
// do something
}

Return (true)

It means process is already running. You will might be shutdown the duplicated process.

Return (false)

It means process is not running. So you can run the process normally. If it is the first run, process will create PID file on the path you set.

Example

You can run example code in /examples

First, run the example code.

$ go run example1.go

Second, open the new shell prompt and run the example code one more. Then, you can see the message the the process is already running. Because you ran the same program over and over again.

About

🕵️ A Package to check whether process is already running for Go(golang)

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages