Command is executed twice


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Command is executed twice
# 1  
Old 04-15-2013
Command is executed twice

Hi

I try to run a command using bash script. The script should now look like this:
Code:
#!/bin/bash
case "$1" in

        start)
                sudo su - cispmgm -c "/usr/local/jdk/bin/java -Dworking.dir=/opt/ibm/cisp -Denvironment.target= -Xms512M -Xmx1024M -classpath /opt/ibm/cisp/:/opt/ibm/cisp/conf:/opt/ibm/cisp/lib/AIB-CispClient-1.2.0-SNAPSHOT.jar ch.coop.aib.v1.job.Run -d /opt/ibm/cisp --start">/opt/ibm/cisp/log/console.log 2>&1 &
        ;;
        stop)
        ;;

        restart)
                $0 stop
                sleep 30
                $0 start
                ;;

        *)

        echo "usage: $0 (start|stop|restart)"

esac

If I start the script as a normal user with the following command: ./startcisp.sh start

If the command is executed twice in the script:

Code:
cispmgm   7404     1  0 10:43 pts/3    00:00:00 su - cispmgm -c /usr/local/jdk/bin/java -Dworking.dir=/opt/ibm/cisp -Denvironment.target= -Xms512M -Xmx1024M -classpath /opt/ibm/cisp/:/opt/ibm/cisp/conf:/opt/ibm/cisp/lib/AIB-CispClient-1.2.0-SNAPSHOT.jar ch.coop.aib.v1.job.Run -d /opt/ibm/cisp --start
cispmgm   7405  7404 11 10:43 ?        00:00:02 /usr/local/jdk/bin/java -Dworking.dir=/opt/ibm/cisp -Denvironment.target= -Xms512M -Xmx1024M -classpath /opt/ibm/cisp/:/opt/ibm/cisp/conf:/opt/ibm/cisp/lib/AIB-CispClient-1.2.0-SNAPSHOT.jar ch.coop.aib.v1.job.Run -d /opt/ibm/cisp --start

if I kille Task 7405 (the second), the first task is terminated automatically. If I but the task kille 7404, continues the second and the program also runs correctly.

What can I do so I do not get two tasks?
My system is a Linux.

Thanks for the help and greetings
Nico

Last edited by DukeNuke2; 04-15-2013 at 06:11 AM..
# 2  
Old 04-15-2013
Please note that PID: 7405 is the child process of PID: 7404

When you kill PID: 7405 (child process), PID: 7404 (parent process) dies automatically because it was just waiting to collect the exit status of its child.

But if you kill the PID: 7405 (parent process), PID: 7405 (child process) becomes a "zombie" and kernel re-parents it to PID: 1 (init process).

So the conclusion is they are not literally separate tasks. They are supposed to be running that way.
# 3  
Old 04-15-2013
Quote:
Originally Posted by Yoda
But if you kill the PID: 7405 (parent process), PID: 7405 (child process) becomes a "zombie" and kernel re-parents it to PID: 1 (init process).
That's an orphan, not a zombie.

A process becomes a zombie when it exits/dies and its parent is alive but not waiting on it. The system is forced to keep a process table entry for that child, in case the parent at some point decides that it cares about the exit status.

When a negligent parent exits (or a dutiful parent is killed), init adopts its children and waits on them. If some of the children had become zombies, they can now finally rest in peace as the kernel reaps them from the process table.

Regards,
Alister

P.S. BRAAAIIIIIIIINS!!! Smilie

Last edited by alister; 04-15-2013 at 02:11 PM..
This User Gave Thanks to alister For This Post:
# 4  
Old 04-15-2013
Quote:
Originally Posted by alister
P.S. BRAAAIIIIIIIINS!!! Smilie
Oops.. I regret calling a poor orphan a zombie.

I should have thought it when I noticed that OP killed it successfully. But usually kill command has no effect on a zombie process.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Set Command to output a log of every command executed in the script

Hi Guys, I like to output every command executed in the script to a file. I have tried set -x which does the same. But it is not giving the logs of the child script which is being called from my script. Is there any parameters in the Set command or someother way where i can see the log... (2 Replies)
Discussion started by: mac4rfree
2 Replies

2. Shell Programming and Scripting

Need to echo command successful if command is executed successfully

Hello, I have written a command n shell script : srvctl relocate service -d t1 -s s1 -i i1 -t t1 -f If the above command executes successfully without error I need to echo "Service relocated successfully and If it errors out I need to trap the errors in a file and also need to make... (1 Reply)
Discussion started by: Vishal_dba
1 Replies

3. Shell Programming and Scripting

Command is executed twice

Hi I try to run a command using bash script. The script should now look like this: #!/bin/bash case "$1" in start) sudo su - cispmgm -c "/usr/local/jdk/bin/java -Dworking.dir=/opt/ibm/cisp -Denvironment.target= -Xms512M -Xmx1024M -classpath... (1 Reply)
Discussion started by: nikolai.straess
1 Replies

4. AIX

Script not getting executed via cron but executes when executed manually.

Hi Script not getting executed via cron but executes successfully when executed manually. Please assist cbspsap01(appuser) /app/scripts > cat restart.sh #!/bin/ksh cd /app/bin date >>logfile.out echo "Restart has been started....." >>logfile.out date >>logfile.out initfnsw -y restart... (3 Replies)
Discussion started by: samsungsamsung
3 Replies

5. Shell Programming and Scripting

System Command dies even when command gets executed successfully

Hi I have created a perl script & running it using Linux machine. I want my script to die when system command is unsuccessful but script is dying even when system command gets executed successfully. :wall: I am using the command below :- system($cmd) || die "FAILED $!"; print "Hello"; ... (2 Replies)
Discussion started by: Priyanka Gupta
2 Replies

6. Shell Programming and Scripting

How command is executed

as i have been new to unix can any one can tell,when be type a command on unix shell what processing it goes through before execution of it (1 Reply)
Discussion started by: shashank1311
1 Replies

7. Shell Programming and Scripting

Need help! command working ok when executed in command line, but fails when run inside a script!

Hi everyone, when executing this command in unix: echo "WM7 Fatal Alerts:", $(cat query1.txt) > a.csvIt works fine, but running this command in a shell script gives an error saying that there's a syntax error. here is content of my script: tdbsrvr$ vi hc.sh "hc.sh" 22 lines, 509... (4 Replies)
Discussion started by: 4dirk1
4 Replies

8. Windows & DOS: Issues & Discussions

OpenSSH command not executed

OpenSSH does not execute commands when they are issued from the command line. I connect from a Win PC to a Win server (2003), using openssh. If I type the name of the bat file from the prompt, it starts. But when I add the command to the ssh command it does not work: ssh -vvv -i "keyname.key"... (4 Replies)
Discussion started by: DocBrewer
4 Replies

9. Cybersecurity

Help Required: Command to find IP address and command executed of a user

Hi, I am trying to write a script which would figure out who has run which command and their IP. As i dont have any clue as to which commands would do this job, i request some gurus to help me on this. Thanks Vishwas (2 Replies)
Discussion started by: loggedout
2 Replies

10. UNIX for Advanced & Expert Users

Any way to know wt command has been executed from last 2-3 days ?

Is there any way to know, what I have executed on UNIX Command prompt from last 2-3 days ? One more point, some systems are interconnected, is there any way to know, who others have executed what command from last 2-3 days ? I am in big trouble guys. Please help me out ASAP. I am working in... (3 Replies)
Discussion started by: manoja422002
3 Replies
Login or Register to Ask a Question