LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-26-2016, 09:06 AM   #1
dpriz
LQ Newbie
 
Registered: Apr 2016
Posts: 1

Rep: Reputation: Disabled
Cron job zombie


Hi all,

I'm new to the forum and looking for some help. This script, running as a cron job is creating a zombie process when it executes the startup/shutdown commands. Can someone help me to understand why?
Code:
#!/bin/bash

#first see if the processes are running
if  pgrep "java" > /dev/null
then
    echo "INFORMATION: Java container is running" >> ./container_util.log
    exit 0
#if not running restart the container
else
    echo "INFORMATION: Java container is not running" >> ./container_util.log
#Get the container name
    container=$(ls /path/to/file | grep nd_)
    echo $container
    echo "INFORMATION: retrieved the container name, $container" #>>.container_\
util.log
#Shutdown the container
    comm="/path/to/ShutdownScript.sh $container"
    echo "INFORMATION: Command being sent $comm"  #>> ./container_util.log
    eval $comm
    sleep 3
#Startup the container
    comm="/path/to/StartupScript.sh $container -bg"                    echo   eval $comm
    echo "INFORMATION: Command being sent $comm"  #>> ./container_util.log
#confirm the container is running
    sleep 3
fi

#Final check whther the container is running
if pgrep "java" #>>./container_util.log
then
    echo "SUCCESS: Java container is running" #>> ./container_util.log
    exit 0
else
 echo "ERROR: Restart failed!"
    exit 1
fi


I get the following the logs:

Sun Apr 24 01:30:02 EDT 2016 INFORMATION: Shutdown command being sent
Sun Apr 24 01:30:05 EDT 2016 INFORMATION: Startup command being sent
Sun Apr 24 01:30:08 EDT 2016 SUCCESS: Java container is running
Sun Apr 24 02:00:01 EDT 2016 INFORMATION: Java container is running
Sun Apr 24 02:30:01 EDT 2016 INFORMATION: Java container is running
Sun Apr 24 03:00:02 EDT 2016 INFORMATION: Java container is running


Right after the success, it seems to create a zombie process, and I can't understand why this is. Any help the group can offer would be awesome.

Thanks,
Dave
 
Old 04-27-2016, 04:26 AM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Where is the zombie process? It seems your script runs properly.
 
Old 05-02-2016, 01:28 PM   #3
X-LFS-2010
Member
 
Registered: Apr 2016
Posts: 510

Rep: Reputation: 58
yes, show your "ps ax", show us the zombie

let's assume if cron script causes error you might get strange effects (though that may be wrong)

i beleive your script can "exit 1" without hitting the exit 1

if any statement is false, exit is 1

so if and if is UNTRUE, and control flow hits bottom: your exit 1.

your script can exit 1 without ever hitting your intended exit 1, i think

using "if" questionbly to plow through the script you should have "exit 0" at the end of the script, so that only your "exit 1" statement can "exit 1"

you'll frequently see in other sh scripts "exit 0" or "return 0" at the end, for the same reason

Last edited by X-LFS-2010; 05-02-2016 at 01:42 PM.
 
Old 05-02-2016, 01:30 PM   #4
X-LFS-2010
Member
 
Registered: Apr 2016
Posts: 510

Rep: Reputation: 58
another possible (i'm unfamiliar with your container thing)

is if you are starting a 2nd container which doesnt like running when one is already running

i can't tell from where i sit if that might be occuring
 
Old 05-02-2016, 01:32 PM   #5
X-LFS-2010
Member
 
Registered: Apr 2016
Posts: 510

Rep: Reputation: 58
comm="/path/to/StartupScript.sh $container -bg"

-bg i assume is background

i'm unsure you understand how cron deals with PID children and & (background); (how cron deals with children and how to "really detatch a child" from cron). yes use of & improperly can cause zombies using cron to show in ps(1) listing. see cron manual and google issues about cron backgrounding and PID and issues like "setsid(1)".

fiddle with that

Last edited by X-LFS-2010; 05-02-2016 at 01:39 PM.
 
Old 05-03-2016, 07:43 AM   #6
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,649
Blog Entries: 4

Rep: Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934
It might not be a good idea to trust such matters to "simple cron," because this daemon merely responds to a timer ... and does not know what it has done in the past.

Let's say that you launch a "background" activity every five minutes, that takes ten minutes to complete. Every five minutes, a new instance is added, and there are two instances active, but cron doesn't know this. Furthermore, if any of the instances "run long," e.g. because of interference caused by the fact that there are two-or-more instances of itself running simultaneously (which never happened in "testing" [sic] on the developer's super-fast machine ...), the instances can start to pile-up.

You might need to use a more-sophisticated daemon: a true batch-execution monitor or distributed processing monitor (e.g. OpenStack, or any one of several batch-job monitoring systems), which are aware of what's going on at all times, and which can schedule work according to an established "work-flow" graph.

cron is a ubiquitous daemon, but it is also a simple one which dates from the 1970's. (Which, [koff, koff ...] is not such a bad thing, really.)
 
Old 05-03-2016, 08:02 AM   #7
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,474

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
Off Topic: "Cron Job Zombie" would make an awesome band name!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cron job starts 6 hours late, rest of cron jobs work fine pieterhouwen Linux - Newbie 33 10-05-2015 12:38 PM
Cron Job Not Running - Looks Like Cron Tried Noble User Linux - Newbie 7 10-26-2014 10:26 AM
how to abort cron if the previous cron job not yet finished? Winanjaya Linux - Newbie 2 05-22-2012 06:44 PM
linux cron job duplicate job question cpthk Linux - Newbie 4 09-11-2009 08:52 PM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 08:16 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration