`

check if program running in linux

阅读更多
In shell,we use the below program to check if some program already running:
export HOMEDIR=/../../
export JAVA_HOME=/usr/lib/jvm/java-1.6.0
export LOGFILE=/tmp/log_`date +"%Y%m%d-%H%M%S"`.log
export JAVA_CMD=$JAVA_HOME/bin/java
export CLASSPATH=$JAVA_HOME/lib/tools.jar:$HOMEDIR/lib/ojdbc-14.jar:$HOMEDIR/lib/log4j-1.2.14.jar:$HOMEDIR/lib/commons-logging-1.1.jar
export MAIN_PROGRAM=com.test.theClassEntry
ps -ef | grep "java" > SomeFile
num=$(wc -l SomeFile | awk '{print $1}')
if [ $num -gt 0 ]
then
        echo "the java process is running" > $LOGFILE
        exit 1
else
        nohup $JAVA_CMD -Xmx10g -Dflag=true -classpath "$CLASSPATH" $MAIN_PROGRAM program_parameter > $LOGFILE 2>&1 &
fi

note:
1.-Dproperty=value
Set a system property value.You can call the following from anywhere in the code to read the properties given on the command line:
String value = System.getProperty("key", "defaultvalue");
2.
http://www.linfo.org/ps.html
An alternative set of options for viewing all the processes running on a system is
ps -ef | less
The -e option generates a list of information about every process currently running. The -f option generates a listing that contains fewer items of information for each process than the -l option.
3.
http://www.thegeekstuff.com/2010/01/awk-introduction-tutorial-7-awk-print-examples/
Awk Example  Print only specific field.

Awk has number of built in variables. For each record i.e line, it splits the record delimited by whitespace character by default and stores it in the $n variables. If the line has 4 words, it will be stored in $1, $2, $3 and $4. $0 represents whole line. NF is a built in variable which represents total number of fields in a record.

$ awk '{print $2,$5;}' employee.txt
Thomas $5,000
Jason $5,500
Sanjay $7,000
Nisha $9,500
Randy $6,000

$ awk '{print $2,$NF;}' employee.txt
Thomas $5,000
Jason $5,500
Sanjay $7,000
Nisha $9,500
Randy $6,000
In the above example $2 and $5 represents Name and Salary respectively. We can get the Salary using  $NF also, where $NF represents last field. In the print statement ‘,’ is a concatenator.
1
0
分享到:
评论

相关推荐

    advanced-linux-programming.pdf

    ARUNNING INSTANCE OF A PROGRAM IS CALLED A PROCESS. If you have two terminal windows showing on your screen, then you are probably running the same terminal program twice—you have two terminal ...

    AnsoftDesignerV6win32crack

    123456 Ansoft Designer v6 win32 version fix 1, copy license.lic into $install\Ansoft\admin folder ...The fix only valid running in 32 bit windows , NOT for LINUX or 64 bit windows!!!!!! 123456 解压

    8-07-14_MegaCLI for linux_windows

    SCGCQ00364411 (DFCT) - Segmentation Fault while running discard preserved cache in megacli Installation Commands: ======================= Run MegaCli from the Command Prompt. Use -h option to see ...

    start-stop-daemon

    -x|--exec <executable> program to start/check if it is running -p|--pidfile <pid-file> pid file to check -c|--chuid |uid[:group|gid]> change to this user/group before starting process -w|--chdir ...

    Senfore_DragDrop_v4.1

    Drag and Drop Component Suite ...If you have registered for update notification via the installation program, you will receive email notification when a new release is available. You will not be notified...

    eric5-5.3.1

    started as a standalone program by executing the eric5-webbrowser script. Please note, the first time you start eric5 it will recognize, that it hasn't been configured yet and will show the ...

    videodog0.31.tar.gz

    ideodog is a command line tool, just based on a stock linux distro, with no need of special libraries, or graphic enviroment ( as xlib, imlib). The only special lib is jpeglib, present in most of ...

    squashfs2.2-r2.tar.gz

    As squashfs is a read-only filesystem, the mksquashfs program must be used to create populated squashfs filesystems. SYNTAX:mksquashfs source1 source2 ... dest [options] [-e list of exclude dirs/...

    Google C++ Style Guide(Google C++编程规范)高清PDF

    If an inline function definition is short, with very little, if any, logic in it, you should put the code in your .h file. For example, accessors and mutators should certainly be inside a class ...

    squashfs1.3r3.tar.gz

    As squashfs is a read-only filesystem, the mksquashfs program must be used to create populated squashfs filesystems. Beginning with Squashfs 1.2, mksquashfs will also append directories and files to ...

    计算机网络第六版答案

    Third, if ISPs decide to charge more money to highly profitable content providers (in countries where net neutrality doesn't apply), the content providers can avoid these extra payments. 16. The ...

    JLink_Windows_V648.zip

    DLL: RISC-V: Reset could fail with "core did not halt after reset" even if the core halted correctly. Fixed. DLL: Re-attaching to existing debug session after connecting and disconnecting once via ...

    ICS delphixe10源码版

    If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and ...

    Bochs - The cross platform IA-32 (x86) emulator

    [3009767] guest RFLAGS.IF blocks externel interrupt in VMX guest mode [2964655] VMX not enabled in MSR IA32_FEATURE_CONTROL [3005865] IDT show bug [3001637] CMOS MAP register meaning error ...

    Securing PHP Web Applications.pdf

    Changing File Permissions in UNIX, Linux, and Mac OS X 76 Changing Windows File Permissions 77 Changing File Permissions in PHP 87 Patching the Application to Allow User-Uploaded Image Files 88 Modify...

    DebuggingWithGDB 6.8-2008

    2 Getting In and Out of gdb . . . . . . . . . . . . . . . . 11 2.1 Invoking gdb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1.1 Choosing Files . . . ....

Global site tag (gtag.js) - Google Analytics