Determining if a process is active in UNIX


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Determining if a process is active in UNIX
# 1  
Old 02-06-2014
Determining if a process is active in UNIX

We have written a bare bones scheduling app using bash scripts. The input to the scheduler is from a mainframe scheduling tool, and the scripts exit code is returned to the MF. The problem is that every now and again I have a script that does not complete and this is left in my Q. I am in the process of writing a clean up script that would run every now and again to find these rogue scripts and clean them out of my running Q. When executing the script I store the PID. The heart of my cleanup script is to determine if the PID is still active.

I have tried various methods to determine this including ps -p $id and kill -0 $id, but none seems to give me the result I require. I understand that the kill option might not work if I am not the process owner and I have read all the documentation on the ps command, but I can not find an answer to my question.

My script looks like this currently:
Code:
  for file in *     # Check all entries in the 'Running' directory
  do
    if [ -f $file ]
    then

      Pidfl="${dir2}/${file}.pid"    #Set up file that contains PID

      Pidfl2="${dir1}/${file}"

      if [ -f $Pidfl ]         #If the PID file is still in the directory
      then
        Act_Proc=`cat ${Pidfl}`  #Get the PID contained in the file
        echo "$ACT_Proc"
        if kill -0 $ACT_Proc = 0  ####### how do I check if it is still active?:(
          then 
            echo "Now in removing ${file}"
#            mail_remove()
          fi
      else   #no PID found, remove from Q 
        echo "Now in removing ${file}"
#        mail_remove()
      fi
    fi 
  done


Last edited by Scott; 02-06-2014 at 10:46 AM.. Reason: Please use code tags
# 2  
Old 02-06-2014
ps pidnumber should return success if the process is alive and failure if the process is dead. It also prints text so redirect to /dev/null.
This User Gave Thanks to Corona688 For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

active directory equivalent for unix

At the moment we are integrating LDAP in our environment. Compared to Windows this process is much complicated and time consuming. With Windows you had Active Directory and if you create a new server, you just add it to the domain and your finished. Yes, I know Unix is not Windows. Are there... (1 Reply)
Discussion started by: misterx12345
1 Replies

2. Shell Programming and Scripting

Q's on Active Process Time

Is it possible to display active processes' Year,Month,Day,Hour,Minute,Second info of process start time ? Preferbly in the format "YYYY/MM/DD HH:MM:SS" ? I tried to do this with the ps command but it only gets the time or date. Any help will be greatly appreciated. Cheers Steve (4 Replies)
Discussion started by: stevefox
4 Replies

3. Programming

Determining file access perms for current process

Stupid question, but is there an ANSI C stdlib function that will do this for me? I want to pass the function a path and determine if the current process can read/write/execute on the path. I suppose I can whip something up using fstat and then determining the current process's user/group IDs and... (6 Replies)
Discussion started by: DreamWarrior
6 Replies

4. UNIX for Advanced & Expert Users

Rollover/compress log from ACTIVE process

I have some Solaris processes that run weeks at a time that create rather large log files that I would like to archive/compress daily. Instead of stopping the process, what can be done so that the log file is backed up and shrunk, but the process can still log to the open file handle without major... (7 Replies)
Discussion started by: ckmehta
7 Replies

5. UNIX for Advanced & Expert Users

Integrating unix with Active Directory

Hey guys. Maybe this should go in Security, I'm not sure... At my work we make websites. Our development servers for these websites are run on a central Debian linux server which we can SSH into, which also contains all the files for these websites. These files are served to the entire... (1 Reply)
Discussion started by: nottrobin
1 Replies

6. Shell Programming and Scripting

How to get active connections in Unix

Hi All, I have to find out how many active connections with other machines are there,then list the remote machine IP address and type of connection. When u say type of connection what does it means TCP,UDP ram. then what is UNIX active connection Please let me know as soon as possible. ... (3 Replies)
Discussion started by: jatin.jain
3 Replies

7. Shell Programming and Scripting

vmstat returns good val for cpuIdle put ps shows no active process

hi i'm running a shell script that checks the amount of cpu idle either using /usr/bin/vmstat 1 2 or sar 1 2 (on unixware) before i run some tests(if cpu idle greater than 89 I run them). These tests are run on many platforms, linux(suse, redhat) hp-ux, unixware, aix, solaris, tru64. ... (5 Replies)
Discussion started by: OFFSIHR
5 Replies

8. UNIX for Dummies Questions & Answers

Similiar to active directory in Unix?

Hi all, If Windows server have an active directory and active folder/mapping(maybe in unix NFS). Is there any similiar fuctions in unix. Actually if we have a hundred client in unix/linux with unix server, I want to manage user client and access control easier as in windows. Thank you in... (5 Replies)
Discussion started by: blesets
5 Replies

9. UNIX for Dummies Questions & Answers

Active Directory and UNIX

Hello - I have a very vague question, which will probably result in vague answers because I don't have a lot of detailed information and I don't know a whole lot about active directory. Our Windows/NT admin has been rolling out Active Directory over the past several weeks and as time goes on,... (1 Reply)
Discussion started by: rm -r *
1 Replies

10. Windows & DOS: Issues & Discussions

unix and active directory

Hi Does anybody know the steps and requirements of the installation process of Windows Active Directory using Unix/Linux Bind DNS. I will appreciate if somebody gives the answer. (1 Reply)
Discussion started by: Darwin Rodrigue
1 Replies
Login or Register to Ask a Question