Discuz! Board

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2029|回复: 7

[Shell] Unix Chell 检查指定进程是否存在 [复制链接]

Rank: 8Rank: 8

发表于 2012-9-14 18:04:56 |显示全部楼层
用cshell检查指定进程是否存在,如果不存在就启动该进程
复制代码
  1. #!/bin/csh
  2. # Script Name: InvanTest check script for all trim devices
  3. # Function : check InvanTest availability before program loading
  4. # Rev0 - First release
  5. # By:
  6. ###################################################################
  7. # this scripts need to be released to /home3/msl/.ad6548_silveroff/
  8. # and update trim_device_list to /home3/msl/.ad6548_silveroff/
  9. ###################################################################
  10. set igft_chk_bypass=0 #maybe one day we need to bypass this check, just set to 1 to bypass
  11. #### check whether bypass invantest check ####
  12. if ( $igft_chk_bypass == 1) then
  13. goto IGFT_SKIP_CHECK
  14. endif

  15. #### check trim dev list ####
  16. set trim_dev_list="/home3/msl/.ad6548_silveroff/trim_dev_list.txt"
  17. set igft_temp_file="/home/local_summary/igft_chk.temp"
  18. set trimed_dev=0
  19. if ( -f $trim_dev_list ) then
  20. foreach record(`sed -n "/${DEVICE_ID}/p" $trim_dev_list`)
  21. set trimed_dev=`expr $trimed_dev + 1`
  22. end
  23. if ( $trimed_dev == 0 ) then
  24. echo "++++ this is not trim device ++++"
  25. goto IGFT_SKIP_CHECK
  26. endif
  27. else
  28. echo "++++ trimming devices list missing ++++"
  29. goto IGFT_SKIP_CHECK
  30. endif

  31. #### start this invan test check ####
  32. set igft_file="/floor/bin/xigft"
  33. set wait_times=5
  34. set igft_launch=0
  35. set igft_locked=0
  36. set init_wait_times=5

  37. #### check process first to find any igft process running ####
  38. echo ""
  39. echo "checking igft process..."
  40. IGFG_PROCESS_CHECK:
  41. set igft_pro=0
  42. foreach record(`ps -a|sed -n '/igft.td/p'`)
  43. set igft_pro=`expr $igft_pro + 1`
  44. end
  45. set igft_pro=`expr $igft_pro / 4`
  46. if ( $igft_pro > 0) then
  47. echo "-->igft is running, you can start lot now"
  48. #setenv and goto end
  49. goto IGFT_CHECK_PASS_END
  50. else
  51. #### check whether locked ####
  52. if ( $wait_times == 5 || $wait_times == 0 ) then
  53. set igft_pro=0
  54. foreach record(`ps -a|sed -n '/igft/p'`)
  55. set igft_pro=`expr $igft_pro + 1`
  56. end
  57. set igft_pro=`expr $igft_pro / 4`
  58. if ( $igft_pro > 0) then
  59. set igft_locked=1
  60. echo "-->igft is not running properly\!"
  61. goto IGFT_CHECK_FAIL_END
  62. endif
  63. endif
  64. #### no igft process found ####
  65. if ( $igft_launch == 1 ) then
  66. echo "-->still can not find igft process, $wait_times times to try..."
  67. goto IGFT_START_SCRIPT
  68. endif
  69. echo "-->igft is not running\!"
  70. endif


  71. #### check igft start script file ####
  72. echo ""
  73. echo "checking igft software, please wait..."
  74. IGFT_FILE_CHECK:
  75. if ( -x $igft_file ) then
  76. echo "-->igft software has been installed"
  77. else
  78. echo "-->igft software NOT installed"
  79. #setenv and goto end
  80. goto IGFT_CHECK_FAIL_END
  81. endif


  82. #### start igft and wait for a while to check process ####
  83. echo ""
  84. echo "start igft now, please wait until igft check pass\!"
  85. $igft_file &
  86. set igft_launch=1
  87. sleep 4
  88. IGFT_START_SCRIPT:
  89. while ( $wait_times > 0 )
  90. set wait_times=`expr $wait_times - 1 `
  91. sleep 4
  92. #check process again, got to end if found
  93. goto IGFG_PROCESS_CHECK
  94. end
  95. echo "-->igft start failed\!\!"
  96. goto IGFT_CHECK_FAIL_END


  97. #### pass end of igft check script ####
  98. IGFT_CHECK_PASS_END:
  99. echo "IGFT_CHECK_STATUS~PASS" > $igft_temp_file
  100. chmod 777 $igft_temp_file
  101. echo "+-----------------------------------------------------+"
  102. echo "| invantest check pass, you can continue starting lot |"
  103. echo "+-----------------------------------------------------+"
  104. exit 0


  105. #### fail end of igft check script ####
  106. IGFT_CHECK_FAIL_END:
  107. echo "IGFT_CHECK_STATUS~FAIL" > $igft_temp_file
  108. chmod 777 $igft_temp_file
  109. echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  110. echo "x invantest check failed, can not start\! x"
  111. echo "x please inform LSG to check invantest\! x"
  112. echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  113. setenv LD_LIBRARY_PATH /image/bin.rls/custom/qa_custom/scripts/scan_startlot_endlot/STATS/ESUMMARY/lib
  114. if ( $igft_locked == 1) then
  115. echo "x IG.FT most probably locked\! x"
  116. echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  117. /home3/msl/.ad6548_silveroff/Locked_InvanTest_Error &
  118. else
  119. /home3/msl/.ad6548_silveroff/No_InvanTest_Error &
  120. endif
  121. setenv LD_LIBRARY_PATH /image/bin.rls/lib
  122. echo "deleting program ... "
  123. delete
  124. echo "program deleted"
  125. exit 1


  126. #### skip IGFT check, maybe this script need to by pass one day ####
  127. IGFT_SKIP_CHECK:
  128. echo "IGFT_CHECK_STATUS~BYPASS" > $igft_temp_file
  129. chmod 777 $igft_temp_file
  130. echo "+--------------------------+"
  131. echo "| invantest check bypassed |"
  132. echo "+--------------------------+"
  133. exit 0
复制代码

使用道具 举报

Rank: 3Rank: 3

发表于 2014-2-21 10:08:38 |显示全部楼层
好帖要顶,楼主的头像还是不错滴

使用道具 举报

Rank: 2

发表于 2014-5-26 06:20:25 |显示全部楼层
顶!!!!!!!!!!












24V1.5A电源适配器

使用道具 举报

Rank: 2

发表于 2014-6-2 12:52:39 |显示全部楼层
好帖要顶,楼主的头像还是不错滴

使用道具 举报

Rank: 2

发表于 2015-9-19 04:40:30 |显示全部楼层
我也想了解,请大家都说说












3d环球精灵版电视棒 电视棒usb

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

Archiver|IC Test Forum Inc.

GMT+8, 2019-3-24 14:49 , Processed in 0.527511 second(s), 12 queries .

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部