Operating System - HP-UX
1755839 Members
4464 Online
108838 Solutions
New Discussion юеВ

How to switch from one application to another given its pid

 
John M. Liberi Jr.
Occasional Contributor

How to switch from one application to another given its pid

Given that I have obtained the PID of another process running how can I force that process to come to the foreground

1) an executable, foo, has been launched then locked using fcntl.
2) when a user attempts to launch foo a second time a shared lib (the
one i am working on) checks and see that there is a file lock on foo
and therefore will not allow it to be launched a second time.

when the user launched foo the second time i am trying do the following:

the second foo brings the first foo to the top of current workspace.

the problem is that i can not figure out, using c and motif, how to switch to a process that is already running given its pid or trapping a signal. any help would be great.



thanks
john
3 REPLIES 3
Sajid_1
Honored Contributor

Re: How to switch from one application to another given its pid

If you are looking for simple solutions, then use 'bg' and 'fg' commands to switch processes back ground and fore ground with their job IDs:

# man bg
# man fg
learn unix ..
John M. Liberi Jr.
Occasional Contributor

Re: How to switch from one application to another given its pid

Sajid,
thanks but i don't think this would be an acceptable solution at my work place.

john
Gregory Fruth
Esteemed Contributor

Re: How to switch from one application to another given its pid

By "background" and "foreground" you're talking
about window stacking and focus and not the
process state, right? I believe window stacking
and focus are the responsibilities of the window
manager, so you're going to have to figure out
what method your window manager uses.
If you're using CDE, it appears that you can
use the Raise message (see "man Raise")
to raise a window. You'll have to poke around
in the CDE docs to figure out how to use it.

As for signalling a process by PID, it's probably
easiest to just send it a SIGUSR1 or SIGUSR2
using the kill() syscall (not the "kill" command).
Set up a signal handler in your process which
invokes your raise/focus function when the
process receives SIGUSR.

HTH