I'm executing a shell script using NSTask but the problem is that the shell script is one of those scripts that keeps running until you press control+c. It starts up fine but then my mac application just waits for it to end. How can I make it so that it detaches the task from the mac application and goes and runs it in a background.
Don't call waitUntilExit or otherwise run the task synchronously. If the task has lots of output, make sure you read and process the data or else an i/o buffer will fill and it'll block.
In general, you shouldn't be using NSTask for a daemon like operation anyway. You should be using launchd.
Related
I'v started a process with valgrind to find the leaks with the option --leak-check=full and redirecting the stdout and stderr outputs to a file. But the program seems to be running too long and now I want to send the process to the background so that I can close the terminal and check on the results at later time.
Here I've found that by using ctrl +z it will suspend the process and with bg and disown commands its possible to remove the process from the terminal and run on the background
But when I try that with valgrind the process doesnot respond to the ctrl + z command
Is there an alternative way to send the valgrind process to background? Or am I doing the whole thing wrong?
Just for the sake of the question, say I open a terminal an log into my Linux computer. I run a program that keeps outputting information on my screen, looping. I close the terminal window, and the program shuts down.
I set up a cronjob or a startup script that launches the same program as in example 1. The program is looping now, run as root.
I open a terminal, and log into my computer through SSH. Can I make a Bash script that retrieves the output of said program, even if it's running somewhere in the background? I mean, is the program "virtually" outputting information (as in example 1)?
The program closes stdout and stderr when it exits. Looping it as you describe will just cause it to start and exit continuously. You could look at redirecting stdout and stderr.
I have a Jython script that is meant to run as a daemon in background, but somehow it doesn't start at all when I'm trying to run it in background.
So I've tried to do a most basic "hello world" script, it works fine if I execute it in console like
./mysqript.py
But same script executed like
./mysqript.py &
fails. It doesn't output error messages, it doesn't throw exceptions, it's actually not even quitting silently. It's just hanging forever in the process list as a zombie process doing nothing.
Why is that and how can I make it work?
PS: Environment is Jython2.7 beta.
Glassfish v3 is launched as follows:
./bin/asadmin start-domain <domain-name>
This script eventually runs:
exec "$JAVA" -jar "$AS_INSTALL_LIB/admin-cli.jar" "$#"
admin-cli.jar eventually launches another process, effectively putting itself into the background.
I would like to launch glassfish without putting itself in the background for the purpose of monitoring with daemontools (ie: svc). Is this possible?
The documentation talks about using inittab here which seems like it would also require a way to launch it without forking or backgrounding so some other process (eg: inittab, evc, etc.) can watch the process id and restart it if it crashes. However, in this inittab example, is it using the same backgrounding cmd line, so I don't know how inittab can possibly respawn the process when it doesn't know what process id to watch. Am I missing something?
You should be able to use asadmin start-domain -v...
Note: log statements are sent to the log file AND System.out/System.err.
hi i am new to valgrind. I know how to run valgrind on executable files from command line. But how do you run valgrind on server processes like apache/myqld/traffic server etc ..
I want to run valgrind on traffic server (http://incubator.apache.org/projects/trafficserver.html) to detect some memory leaks taking place in the plugin I have written.
Any suggestions ?
thanks,
pigol
You have to start the server under Valgrind's control. Simply take the server's normal start command, and prepend it with valgrind.
Valgrind will attach to every process your main "server" process spawns. When each thread or process ends, Valgrind will output its analysis, so I'd recommend piping that to a file (not sure if it comes out on stderr or stdout.)
If your usual start command is /usr/local/mysql/bin/mysqld, start the server instead with valgrind /usr/local/mysql/bin/mysqld.
If you usually start the service with a script (like /etc/init.d/mysql start) you'll probably need to look inside the script for the actual command the script executes, and run that instead of the script.
Don't forget to pass the --leak-check=full option to valgrind to get the memory leak report.