I have a small graphical application whose only purpose is to pop up certain types of messages. Currently, I'm using it in a Bash script like this:
What I want to do is after the while loop is over (it does break out eventually, no infinite loop there), end MyProg so the message disappears.
I tried to do that by killing the process ID, like this:
But the pid was empty. I then tried to run MyProg in the background
:
And got a pid, but then the kill command said that the pid didn't exist.
Is there something else I'm missing here, or a better way to do this besides kill?
If MyProg forks itself into the background, you won't be able to capture it's PID. This seems to be the case. Perhaps the documentation of MyProg can shed some light on it, or it's behavior can be changed to stay in the foreground, in which case you'd be able to use your second approach.
I can only get a pid when MyProg is in the background, that's the weird thing. If the process is in the foreground, the process id is empty. I wrote MyProg myself, and it doesn't have anything in it that would make it preferentially do anything in the background or foreground.
The definition of $! is "Expands to the process ID of the most recently executed background (asynchronous) command."
But since I assume your while loop runs after using MyProg without &, then MyProg must be forking itself into the background and therefore the shell hasn't a way to know the PID anyway, even if it backgrounds MyProg.
./MyProg & pid=$!
$pid may end up being 1234, but MyProg does a fork() and continues running at 1238 ... How would we know that number?
This User Gave Thanks to neutronscott For This Post:
I have been having an extremely annoying problem. For the record, I am relatively new at this. I've only been working with unix-based OS's for roughly two years, mostly Xubuntu and some Kali. I am pretty familiar with the BASH language, as that's the default shell for debian. Now, I've made this... (16 Replies)
I don't expect any quick answers, but if people have links to resources I can investigate I'd be extremely appreciative. Here is what we have today:
The "application" is a multi-process train control system that uses the Unix desktop, currently CDE, several motif-based applications and sound,... (8 Replies)
Hi guys,
i need to write a shell script that will close file descriptors from /proc/pid/fd
will calling exec 4<&- solve the problem ?
thanks in advance :) (15 Replies)
Hi,
I want to invoke(run) a graphical application remotely, and the display should be in remote itself. (no X redirect).i want to do this through ssh.
like if i login to a remote machine and run firefox it should display there itself.
how can i do this..? (2 Replies)
Hi,
I need to get the pid of a process and have to store the pid in a variable and i want to use this value(pid) of the variable for some process. Please can anyone tell me how to get the pid of a process and store it in a variable. please help me on this.
Thanks in advance,
Amudha (7 Replies)
I'm writing some software tests, & one of my test cases is to prevent an address space from closing a data file (file is closed & a new one opened every 15 minutes).
I can't remove or rename the file while it's being written to, any other ideas to prevent a file from being closed - or at least... (4 Replies)
1. If I use an software application(which connects to the database in the server) in my local pc, how many PID should be registered? Would there be PID for the session and another PID for socket connection?
2. I noticed (through netstat) that when I logged in using the my software application,... (1 Reply)
question: for the below program
i just printed the value for pid, child pid and parent pid
why does it give me 6 values? i assume ppid is 28086
but can't figure out why there are 5 values printed instead of just two!
can someone comment on that!
#include<stdio.h>
#define DIM 8
int... (3 Replies)
Hi all
Is there a command that I can use to close out open ports?
I did a netstat - a -p and got a long list of ports open (see sample below). I have disabled the some of the applications from /etc/services/. But there are still applications listening on certain ports.
I need to know how to... (6 Replies)