LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-10-2005, 04:15 AM   #1
ealdaz
LQ Newbie
 
Registered: Jun 2004
Posts: 7

Rep: Reputation: 0
Shell script's name doesn't appear in ps


Hi everyone:

I have a script that runs in a infinite loop, repeating the same action in another script regularly.
I neet to be able to kill it from a process called by crontab should the need arise. However, the name of the script does not show up in the ps listing, even though it is clearly running in the other window.

Instead i can only see the entry sh , instead of the actual name of the script, so can't use killall to kill it, as there are many sh entries.

Is there a way to make the script's name appear in the ps output?

Thanks
Eduardo
 
Old 08-10-2005, 04:33 AM   #2
chil326
Member
 
Registered: Jul 2004
Location: Paris, France
Distribution: mandriva LE 2005
Posts: 86

Rep: Reputation: 15
Re: Shell script's name doesn't appear in ps

Quote:
Originally posted by ealdaz
Hi everyone:

I have a script that runs in a infinite loop, repeating the same action in another script regularly.
I neet to be able to kill it from a process called by crontab should the need arise. However, the name of the script does not show up in the ps listing, even though it is clearly running in the other window.

Instead i can only see the entry sh , instead of the actual name of the script, so can't use killall to kill it, as there are many sh entries.

Is there a way to make the script's name appear in the ps output?

Thanks
Eduardo
another solution is to use a file in /Var where you write the pid of the script when it executes
then you just have to read the pid and use kill
however that's strange that your process doesn't appear in ps
hope this helps

Last edited by chil326; 08-10-2005 at 04:35 AM.
 
Old 08-10-2005, 04:36 AM   #3
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 66
what does "ps -le" give?

Yves.
 
Old 08-10-2005, 06:03 AM   #4
ealdaz
LQ Newbie
 
Registered: Jun 2004
Posts: 7

Original Poster
Rep: Reputation: 0
If i do ps -le i get
....
1568 root 1580 S -sh
1591 root 908 S pppd call gprs
1613 root 1596 S sshd: root@pts/1
1615 root 1540 S -sh
1630 root 1584 S -sh
1632 root 1108 S /bin/sh ./ftp-send file.zip
1633 root 836 S ftp -n ftp-host

process 1630 is the script that calls ftp-send repeatedly
as you can see it appears as -sh not by it's proper script name.
 
Old 08-10-2005, 07:28 AM   #5
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 66
Then maybe run ps as to display a PPID column (Parent PID), and use the PPID of the ftp-send line. Does this help:
ps -e o pid,ppid,cmd

Yves.
 
Old 08-10-2005, 09:37 AM   #6
ealdaz
LQ Newbie
 
Registered: Jun 2004
Posts: 7

Original Poster
Rep: Reputation: 0
Good idea, unfortunately i'm running linux on an arm machine and in order to save resources the ps i think is from busybox (an executable that implements ps,ls, cat, and many other common commands and saves a lot of space), but unfortunately it doesn't have those options
:-(

I think i might be stuck, i've also tried running my script as
. ./script
to stop the current shell from creating another shell to execute my script, but it doesn't make much difference, a new shell is not created, but still the name of the process still doesn't appear
 
Old 08-10-2005, 09:58 AM   #7
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 66
Do you have the procfs filesystem mounted on /proc. If this is the case, then one of those two commands may help you:
Code:
grep -l 'part of a command line' /proc/*/cmdline
grep PPid /proc/<aKnownPid>/state
Yves.

Last edited by theYinYeti; 08-10-2005 at 09:59 AM.
 
Old 08-10-2005, 09:47 PM   #8
bhar0761
Member
 
Registered: Jul 2005
Location: San Francisco
Distribution: Fedora Core 6
Posts: 64

Rep: Reputation: 15
Interesting, can we look at the script to see where the problem may be located.
 
Old 08-11-2005, 05:14 AM   #9
ealdaz
LQ Newbie
 
Registered: Jun 2004
Posts: 7

Original Poster
Rep: Reputation: 0
Of course:
The file is called gprstest
I call it as root as:
> ./gprstest

File contents:

#Continuously send the zip file to keep connection busy
again=yes
while [ "$again"=yes ]
do
echo started:`date` > time.txt
./ftp-send file.zip
sleep 1
echo finished:`date` >> time.txt
done

Before i forget, i'd like to thank you all for your help, it's much appreciated
 
Old 08-11-2005, 10:36 AM   #10
bhar0761
Member
 
Registered: Jul 2005
Location: San Francisco
Distribution: Fedora Core 6
Posts: 64

Rep: Reputation: 15
Just a quick question.
Do you have a header tag to tell what shell to execute? For example,
#!/bin/bash

Brian
 
Old 08-17-2005, 05:43 AM   #11
ealdaz
LQ Newbie
 
Registered: Jun 2004
Posts: 7

Original Poster
Rep: Reputation: 0
Well spotted !! brilliant.
That was exactly the problem, i can't believe i forgot to add it, how silly is that! thank you very much !

Out of curiosity, without that first line the file was still executed as an sh script, so what extra information are we giving by specifying a particular shell to use? I mean, the parent shell seemed to be able to figure out that it was a script as it was executable and just spawned a new sh shell to run it, so why does adding #!/bin/sh make the parent shell actually give it a name, ie:
/bin/sh ./gprstst
instead of just
/sh
as was the case before?

Thanks again.
 
Old 08-17-2005, 11:54 AM   #12
bhar0761
Member
 
Registered: Jul 2005
Location: San Francisco
Distribution: Fedora Core 6
Posts: 64

Rep: Reputation: 15
When running a script in a subshell, you should define which shell should run the script. The shell type in which you wrote the script might not be the default on your system.

I believe it has something to do with the subshell.

B
 
Old 08-21-2005, 09:27 PM   #13
bhar0761
Member
 
Registered: Jul 2005
Location: San Francisco
Distribution: Fedora Core 6
Posts: 64

Rep: Reputation: 15
when you use:
#!/bin/bash

It spawns a new shell and hence creates a new process instead of using the existing shells that it was executed in.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
'sh' shell - Actually calls legacy Bourne shell, or uses system default? Dtsazza Linux - Software 1 10-28-2005 09:20 AM
Log all of a shell script's I/O to the console and a file trevelluk Programming 8 04-18-2005 01:40 PM
[bash] locating script's directory Erhnam Programming 19 02-01-2005 03:45 AM
uid battle: Apache v/s script's owner kires Linux - Networking 3 01-19-2004 03:43 PM
Problem locating Network script's path f00lday Linux - Networking 3 06-05-2003 04:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:46 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