LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Requesting a Feasibility/Sanity Check on a Job Control Issue (https://www.linuxquestions.org/questions/linux-general-1/requesting-a-feasibility-sanity-check-on-a-job-control-issue-834511/)

kevinbenko 09-25-2010 10:05 PM

Requesting a Feasibility/Sanity Check on a Job Control Issue
 
Greetings:

I need a sanity check on something I want to do:

When a user logs out of their session, have the appropriate KDM config file (/etc/kde4/kdm/Xsetup) kill only certain applications from only that particular dead session (xplanet and kmail are the only culprits I've noted, thus far). I don't want other sessions affected.

Is this feasible, and can anyone think of any unintended consequences?

[[I see the potential for race conditions, which tells me that I want to use semaphores.]]

Thank you for your time.

unSpawn 09-26-2010 02:35 AM

First of all if applications like xplanet or kmail appear to be hanging then you should look into the reasons *why*. If it appears to be related to saving data then abruptly interrupting processes may lead to whining and gnashing of teeth (aka data loss). If OTOH they're just slow then maybe that should be fixed by those application developers. What I mean is that treating the cause is preferable to just treating symptoms. As far as process selectors go, if applications are started by the user manually and from within the Desktop Environment then there will be similarities in UID, Parent PID, Session ID et cetera. Take for example Firefox started by its 'firefox' shell script as '/bin/sh /path/to/firefox/firefox -ProfileManager'. Its PID is 'pgrep -f 'firefox -ProfileManager';', so its children are 'pgrep -g $(pgrep -f 'firefox -ProfileManager') -l'. Now DE's may autostart processes (so PPID may be 1) and some processes create other processes. Running a forest display from within ${LOGNAME}s session like this should show: '/bin/ps U $LOGNAME xfo pid,ppid,pgid,sid,sess,uid,cmd --sort=pid' what possibilities you have. In short you could say that unless $LOGNAME has more sessions running in (p)killing processes your widest selector can then be the UID (see with 'pgrep -U $LOGNAME -l') so killing for example 'kmail' could be expressed as 'pkill -9 -u $LOGNAME kmail'. I hope that wasn't too convoluted.

kevinbenko 09-26-2010 05:08 AM

The actual implementation of the killing of the applications isn't a problem (sed+grep+awk on the tail end of logs in /var/log), and the problem isn't with the applications themselves, it's that sometimes processes get pushed into the background and disowned by their parent process via the "&" and the "disown" bash shell command

I'm just looking for possible annoyances that could pop up. I've already accounted for the fact that a single user could be logged into multiple sessions.
Can anyone see any potential race conditions popping up with this sort of thing?
I'm assuming that there will be race conditions, but I can't seem to think of any off the top of my head.


All times are GMT -5. The time now is 02:13 PM.