Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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
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.
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
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?
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.