Programming :: Notify When A Process Closes?
Jan 28, 2011It is possible to know when any process is closed? When I refer to any process, is a process that is not a child of my application.
I thought perhaps pipes in /proc/[pid]/fd/..
It is possible to know when any process is closed? When I refer to any process, is a process that is not a child of my application.
I thought perhaps pipes in /proc/[pid]/fd/..
Running debian wheezy. I noticed recently, whenever I fork a process using "&" from a terminal, such as
Code: Select allleafpad &
it starts up, shows the processid in the terminal, but every time when I close the terminal, leafpad gets killed. However, I create a simple bash script,
Code: Select all#!/bin/bash
leafpad&
exit
The script launches leafpad, then exits out leaving leafpad running, as it should. Is what I mentioned above normal? I'm confused, because I think I used to be able to do this in terminal without it depending on the terminal to stay running.
I guess I'm remembering wrong. As it turns out, commands begun on terminal get closed with terminal unless, as mentioned, you use nohup or start subshell. Process hierarchy and tracking etc.
I have a shell script to identify whether the process is running or not. If the process is not running, then I execute another script file to run my application. Below is my script and saved this script as monitorprocess.sh Code: #!/bin/bash
result=$(ps -ef | grep -v grep | grep "applicationname.sh" | awk '{print $2}')
echo $result
if [ "$result" == "" ];
[code]...
Is there any difference in cpu usage for process in init.rc(runs automatic when boot is happened) and manually running process. Will these both have same priority by default...?
View 1 Replies View RelatedI tried googling but didn't get any answer for this.I have a process called "abc" and it is running with PID "123".I have a putty session opened with PID "999".I am giving kill -TERM 123 from putty session.My process "abc" before dying it should catch the PID of the terminal which provided TERM signal to it.Is there any way to find this out
View 2 Replies View RelatedI have a shell script to identify whether the process is running or not. If the process is not running, then I execute another script file to run my application. Below is my script and saved this script as monitorprocess.sh
Code:
#!/bin/bash
result=$(ps -ef | grep -v grep | grep "applicationname.sh" | awk '{print $2}')
[code]...
I want to kill parent process after "fork()" method. but if I kill parent process with "exit(0)" method, main() thread is terminated as well so child prosess doesn't work anymore. Is there any way to kill only parent process without affecting to child process?
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
[code]....
Consider the following code:
Code:
int main()
{
int i=0;
pid_t pid;
for(i=0;i<2;i++)
[code]....
I get the following output:
Parent: chid_pid=4356 i=0 parent's pid=4355
This is child 4356 i=0
This is child 4357 i=1
[code]....
I can observe instead of two children(as I expect) processes there are three. This is because child process 4356 creates its own child. Why all the messages of the type "This is child X i=Y" are concentrated one under another? How exactly fork works? Is affected by the fact that I have a dual-core processor?
i want a process that can operate as both a TCP echo server and a UDP echo server. The process can provide service to many clients at the same time, but involves a single process that does not start up any other threads.
View 3 Replies View RelatedI tried to get process ID using pidof. It didn't give any error but a blank output at console Code: $ pidof -s instance1
$
But when I use ps -ef, I get the process ID Code: $ ps -ef | grep instance1
root 4174 21661 0 06:52 pts/1 00:00:00 grep instance1
provgw 30220 30219 28 06:46 pts/1 00:01:44 /usr/java/jdk1.6.0_18/bin/java -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
[Code].....
I'm programming a software system that consists of multiple processes. It is programmed in C++ under Linux. and they communicate among them using Linux shared memory.
Usually, in software development, is in the final stage when the performance optimization is made. Here I came to a big problem. The software has high performance requirements, but in machines with 4 or 8 CPU cores (usually with more than one CPU), it was only able to use 3 cores, thus wasting 25% of the CPU power in the first ones, and more than 60% in the second ones. After many, many research, and having discarded mutex and lock contention, I found out that the time was being wasted on shmdt/shmat calls (detach and attach to shared memory segments). After some more research, I found out that these CPUs, which usually are AMD Opteron and Intel Xeon, use a memory system called NUMA, which basically means that each processor has its fast, "local memory", and accessing memory from other CPUs is expensive.
After doing some tests, the problem seems to be that the software is designed so that, basically, any process can pass shared memory segments to any other process, and to any thread in them. This seems to kill performance, as process are constantly accessing memory from other processes.
Now, the question is, is there any way to force groups of process to execute in the same CPU?. I don't mean to force them to execute always in the same processor, as I don't care in which one they are executed, but that would do the job. Ideally, there would be a way to tell the kernel: If you schedule this process in one processor, you must also schedule this "brother" process (which is the process with which it communicates through shared memory) in that same processor, so that performance is not penalized.
How can I programatically know the status of a process if its PID is known?
View 1 Replies View RelatedIs there a way to send/receive messages between 2 process using copy_from_user and copy_to_user ? I'm looking for some article, but did not found anything.
View 1 Replies View RelatedI'm completely new to scripting and I'm trying to figure out how to write a script that will get a list of all the files in a directorywn through any subdirectories.When I have the list I want to o each file in VI and change the fileformat. So far all I have been able to figure out is that VI can do the batch processing and that "ls -R" gets me the recursive file list. I'm still pretty clueless on how to do the batch process with the VI editor. I think I'm supposed to use the Ex mode but I don't know how to get the list of arguments from the filelist into the editor so they can be processed. If it matters the files were all written in a Windows editor and have gotten the MS carriage returns so I want to do a :set ff=unix command on all the files without having to go into each file manually, there are over 300 files that need updated.
View 3 Replies View RelatedIs there any program which gets the CPU and memory of a process ?
View 1 Replies View RelatedI'm trying to build a multi-threaded server "C" program connecting to multiple clients. For various design reasons, I thought of having one port number per client. What is the maximum number of ports my process can handle
View 5 Replies View RelatedHow to list all the threads spawned by a process?
View 4 Replies View RelatedI have been assigned a school project on detecting memory leaks in linux processes. I am reading.. but have found it hard and inefficient to go through the very vast documentation not knowing what to really look for. Could you please give me some guidelines on this subject?
View 4 Replies View RelatedUnfortunately the setuid() function from unistd.h does not effect the supplementary group ids of the process. Is there a way to set them directly? Even better, is there a setuid() equivalent which also sets the process's supplementary gid's to match the user's?
View 2 Replies View RelatedIs the PID of a process changes during it�s life cycle in linux ?Or it�s PID is fixed throughout of process�s life cycle.
View 2 Replies View RelatedI need to ask a question on many forums/mailing lists.In such a situation I need to open browser and login to many forums at the same time.Then go and format it according to forum guidelines and then paste it.So I want to know if I can automate this process some way by some alias or command line utility and just type the question in a text file and give URLs on command line and the question gets posted to those forums where I request?
View 7 Replies View RelatedI would like to send struct data from process A to process B but I dont known what is the best way. I have read about IPC, but there are a lot of ways to do it.
View 2 Replies View RelatedI have doubt regarding cpu sharing between process and threads.In my program iam creating 4threads=> 1 process+4 threads. How is cpu alloted to these all tasks. Is here process is getting cpu time like thread or having more cpu time than threads.
View 1 Replies View RelatedScenario: ( in C++ code)
I need a process A to be able to get the start time of process B. I have the PID of the process B.
I would have thought there would be a simple system call to make by passing in the pid of Process B, but I don't thing there is??!!
So my other thought is to create a script that will be passed the pid and either I can read the file creation of /proc/<PID>/stat or I could also parse the start time of ps on the <PID>. This script can be ran from the C++ code. My difficulty is capturing this information in the C++ code. If I run exec ( or system if not a script) I need the results in a program variable....not stdout.
My only solution is write it to a tmp file and read it back into the program variable. Seems rather arguious but a least it would work.
Background - I need to port Windows code ( GetProcessTimes(creationtime,...))
I am trying to automate some directory naming when we're manually running some scripts and are using tee to direct the output to a file (log). Right now this is what we do
Code:
./some_script.sh 2>&1 | tee /home/user/some_dir/logs/manual/some_script_20110216_1628.log
As a matter of laziness and keeping the log files consistently named, I'd like to create a function to pipe it to so that it's doing all the naming How I envision the command running
Code:
./some_script.sh 2>&1 | myfunc
And what the logfile name should look like (and in the right directory)
Code:
some_script_20110216-1628.log
I was thinking of adding a function to our profile to handle this. Just in testing I was trying to stream line right on the command line, but I'm having some difficulty in getting the name of the script that is pushing data over the pipe. Here is what I've tried
Code:
./some_script.sh 2>&1 | tee $(cd ../logs/manual; pwd)/$0_$(date +%Y%m%d)-$(date +%H%M).log
but that created a file named
"bash_20110216-1628.log"
I am using pthread_create system call to create a thread. However pthread_create does not return the PID ( process ID). Is there any quick way to fınd the PID of the created thread.
View 1 Replies View RelatedMy script in /usr/bin displays the time on the console tty1 :
Quote:
if [ $(echo &>/dev/null > /dev/tty8; echo $?) -eq 0 ]
then
while [ 1 -lt 2 ]
do
[code].....
I'm started this script : /usr/bin/showtime How i can kill process of this script.
I am trying to relaunch a process after it's name, not pid, terminates in C++. Is this possible? I am using g++ 4.3-4.4 on Fedora 10, wandering between my x86 and ppc machines. I just recompile.
View 3 Replies View RelatedI wanted to know how to kill more than one process in unix??
e.g- I have problem statement as
"Write a shell script to Kill all processes started from your login "
I am trying to process an email form using PHP.It is working okay so far but I want the Items to be displayed as a list when the email is received. eg.
one
two
three
four
and not
one two three four
here is a copy of the variable that displays the message