Results 1 to 6 of 6

Thread: distinguishing interactive bash from script bash in ps

  1. #1
    Join Date
    Jan 2010
    Location
    Wheeling WV USA
    Beans
    2,021
    Distro
    Xubuntu 20.04 Focal Fossa

    distinguishing interactive bash from script bash in ps

    i still use bash for many scripts as well as many interactive shell sessions. i want to be able to terminate all the interactive shells or all the script shells for a particular user, but not both. "killall /bin/bash" would do both. i'd like to know the best way to list bash processes in ps that can be filtered to one type or the other.
    Mask wearer, Social distancer, System Administrator, Programmer, Linux advocate, Command Line user, Ham radio operator (KA9WGN/8, tech), Photographer (hobby), occasional tweetXer

  2. #2
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: distinguishing interactive bash from script bash in ps

    Use a PID file for a each "program". Be certain to trap signals so the PID file gets cleaned up regardless of how the process ends. https://www.tldp.org/LDP/Bash-Beginn...l/chap_12.html
    Professional programs should always clean up their temp files regardless of how they finish, even if killed.

    You can use the PID file to know the process and kill them using the PID.
    Last edited by TheFu; October 1st, 2019 at 12:47 AM.

  3. #3
    Join Date
    Jan 2010
    Location
    Wheeling WV USA
    Beans
    2,021
    Distro
    Xubuntu 20.04 Focal Fossa

    Re: distinguishing interactive bash from script bash in ps

    yes, in the case of killing a script that has temporary file, it should clean them up on the appropriate signals. but my issue is determining which processes to kill and which processes to not kill, depending on which set i want killed. the scripts might be called killallbashscripts and killallbashsessions. the latter one will also check to see if it is running under one and kill it last, or try to ignore SIGHUP.
    Mask wearer, Social distancer, System Administrator, Programmer, Linux advocate, Command Line user, Ham radio operator (KA9WGN/8, tech), Photographer (hobby), occasional tweetXer

  4. #4
    Join Date
    Dec 2014
    Beans
    2,566

    Re: distinguishing interactive bash from script bash in ps

    Code:
    ps -a -C bash -o pid,args --no-headers
    will output all process with 'bash' somewhere in the command. A bash executing a script has the name of the script file as one of its arguments.

    Holger

  5. #5
    Join Date
    Oct 2005
    Location
    Lab, Slovakia
    Beans
    10,783

    Re: distinguishing interactive bash from script bash in ps

    You could use a different Group ID using the program 'sg' to launch the script. Then you can manage the programs based on their group IDs

  6. #6
    Join Date
    Jan 2010
    Location
    Wheeling WV USA
    Beans
    2,021
    Distro
    Xubuntu 20.04 Focal Fossa

    Re: distinguishing interactive bash from script bash in ps

    Quote Originally Posted by Holger_Gehrke View Post
    Code:
    ps -a -C bash -o pid,args --no-headers
    will output all process with 'bash' somewhere in the command. A bash executing a script has the name of the script file as one of its arguments.

    Holger
    so, i just need to see if a script name is there, or not.
    Mask wearer, Social distancer, System Administrator, Programmer, Linux advocate, Command Line user, Ham radio operator (KA9WGN/8, tech), Photographer (hobby), occasional tweetXer

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •