kill application from other application on ios 6 using void kill dont work - ios6

i got jailbreak iphone ios 6
in my tweak on ios 4&5 I used (void) kill to close other app running in the background.
this is my code:
#import "SBApplication.h"
SBApplication *app ;
app = [[objc_getClass("SBApplicationController") sharedInstance]
applicationWithDisplayIdentifier:#"my killed program id "];
if(app)
[app kill];
now when i trying that in ios 6 i cant get this to work !
need help?

Just to expand on Victors answer a bit... you want to get the pid from the application and if it is greater than 0(a valid pid), kill it with either SIGTERM(Nicer, though it's not guaranteed to kill it) or SIGKILL(Forceful Termination)
SBApplicationController *appController = [objc_getClass("SBApplicationController") sharedInstance];
SBApplication *app = [appController applicationWithDisplayIdentifier:appId];
if (app.pid > 0)
kill(app.pid, SIGTERM);
Info About Termination Signals:
http://www.gnu.org/software/libc/manual/html_node/Termination-Signals.html

Assuming the second app is yours, you could open the second app with openURL and have it kill itself in the App Delegate callback.

How about good old "kill(pid, signal);"?
If you have appropriate (root?) privileges, it should work for you.

Related

How to quit CefClient totally On MacOS

- (void)terminate:(id)sender {
ClientAppDelegate* delegate = static_cast<ClientAppDelegate*>(
[[NSApplication sharedApplication] delegate] );
[delegate tryToTerminateApplication:self];
// Return, don't exit. The application is responsible for exiting on its own.
}
- (void)tryToTerminateApplication:(NSApplication*)app {
NSLog(#"tryToTerminateApplication ");
client::MainContext::Get()->GetRootWindowManager()->CloseAllWindows(false);
}
I tried “client::MainContext::Get()->GetRootWindowManager()->CloseAllWindows(false); ”,the default root window is been closed,but the CefClient app still in the Dock,then click the app icon,it can not open window again,
My question is why CloseAllWindows cant Terminate the CefClient totally,
How could i achieve this effect?Im An Android dever,know little about CEF on Mac,
Thank you very much anyway,

Apache Prefork/Worker MPM

I'm just beginning to understand how an apache server works, andthe other day I ran into a problem when programming a very simple webpage while displaying a hit count for the page:
/* The simplest HelloWorld module */
#include <httpd.h>
#include <http_protocol.h>
#include <http_config.h>
static int noOfViews = 0;
static int helloworld_handler(request_rec *r)
{
if (!r->handler || strcmp(r->handler, "helloworld")) {
return DECLINED;
}
if (r->method_number != M_GET) {
return HTTP_METHOD_NOT_ALLOWED;
}
noOfViews++;
ap_set_content_type(r, "text/html;charset=ascii");
ap_rputs("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n",
r);
ap_rputs("<html><head><title>Apache HelloWorld "
"Module</title></head>", r);
ap_rputs("<body><h1>Hello World!</h1>", r);
ap_rputs("<p>This is the Apache HelloWorld module!</p>", r);
ap_rprintf(r, "<p>Views: %d</p>", noOfViews);
ap_rputs("</body></html>", r);
return OK;
}
static void helloworld_hooks(apr_pool_t *pool)
{
ap_hook_handler(helloworld_handler, NULL, NULL, APR_HOOK_MIDDLE);
}
module AP_MODULE_DECLARE_DATA helloworld_module = {
STANDARD20_MODULE_STUFF,
NULL,
NULL,
NULL,
NULL,
NULL,
helloworld_hooks
};
What basically happened is when I would refresh the page, the hit counter would go up, but sometimes it would randomly drop in number. Someone told me that it was because of the way the Apache Prefork MPM worked. After reading this:
http://httpd.apache.org/docs/2.0/mod/prefork.html
I understand the problem more, but I'm still not 100% sure whats going on. So the prefork MPM creates a bunch of child processes, some of them idle, and waits for clients to connect, so when I'm refreshing the page, I'm actually connecting to a bunch of different child processes the server is running. However, this module has a limited number of child processes it can keep up at the same time, so sometimes when it kills a process my counter goes down. I'm not entirely sure if this explanation is correct or why exactly the counter drops.
All advice is appreciated.
Yes, either that or you got one of the other Apache processes to serve you the request when the counter went down.
You could try and configure Apache in such a way that it only spawns exactly 1 child process that lives forever, but by doing that you limit Apaches capabilities.
I recommend that you try and keep your module completely stateless. If you want that hit counter, save the state in a file or a database and retrieve it from there when you need it. You could even talk to another process that has the hit counter just in a static variable like your module at the moment.
You are storing your hit count in the noOfViews variable, which means in the memory of a single process.
Whether under worker or prefork MPM, httpd typically spawns multiple child processes. Each will have its own memory storage for noOfViews, so you are only counting the number of hits for that process. When your request is randomly given to a different process, it has a different counter.
You will notice this more for prefork than worker because each prefork process only handles one request at a time, while worker is threaded and may handle multiple; so there are a lot more processes under prefork than worker. But the same thing will occur under either MPM when your requests are directed to different processes.
Also note that restarting httpd, or just killing individual processes, will lose the counter. New processes will start at a count of 0. So, this is not a good approach if your goal is to count hits globally.

Reliably Restart a Single-Instance WPF application

I would like to have my current application close and restart. I have seen many posts on this, however none of these seem to work for me.
I have tried
System.Diagnostics.Process.Start(System.Windows.Application.ResourceAssembly.Location);
System.Windows.Application.Current.Shutdown();
However this only restarts the application once. If I press my 'restart' button again (on the already restarted app), it only closes.
I have also tried launching a new System.Diagnostics.Process and closing the current process, but again this does not restart, it simply closes.
How can I restart my current WPF application?
You could create another application which you start when exiting your app and which in return does start your application again. Kind of like how a patcher would work, only without patching anything. On the plus side you could have a loop in that "restart-application" which checks all running processes for your main application process and only tries to re-start it once it does not appear in the process any longer - and you got the bare bones for a patcher also :) Whilst you do not seem to have a problem with restarting your application due to it still being in the processlist - it is the way I would go for when doing it in a production environment as this gives you the most control IMHO.
Edit:
That part in the button event handler (or wherever you want to restart your app with) of your main app (Process2BRestarted.exe in my case):
private void cmdRestart_Click(object sender, EventArgs e)
{
var info = new ProcessStartInfo();
info.FileName = "ProcessReStarter";
info.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(info);
Application.Exit();
}
This should go into your utility/restarter application (ProcessReStarter.exe over here):
private void MainForm_Load(object sender, EventArgs e)
{
// wait for main application process to end
// really should implement some kind of error-checking/timer here also
while (Process.GetProcessesByName("Process2BRestarted").Count() > 0) { }
// ok, process should not be running any longer, restart it
Process.Start("Process2BRestarted");
// and exit the utility app
Application.Exit();
}
Clicking the restart button will now create a new process ProcessReStarter.exe, which will iterate through the process list of all running processes - checking whether Process2BRestarted is still running. If the process does not appear in the list (any longer) it will now start a new Process2BRestarted.exe process and exit itself.

Wait for WPF app to load after starting with Process.Start()

I have a WinForms app that starts a wpf process running using Process.Start. I would like to know when the WPF process is finished loading and I can access the process.MainWindowHandle property (its 0 before its completly loaded).
I tried polling but the handle is always 0. However, if I debug and wait (after Process.Start) for the WPF app to load - I then will get the correct handle.
Does not work:
int maxCount=100000;
int count=0;
do
{
wpfProcess.WaitForInputIdle();
_hWnd = net4ReconProcess.MainWindowHandle;
count++;
} while (_hWnd.ToInt32() == 0 || count > maxCount);
Add process.Refresh(); to the while loop.
Using a while loop for WaitForInputIdle is a non-sense because this call blocks the current thread until the other process has finished its initialization. After that, it always returns immediately. Please read the post WaitForInputIdle should really be called WaitForProcessStartupComplete – The Old New Thing
As raymond says it, it should really be called WaitForProcessStartupComplete.
You should use this code:
if (!wpfProcess.WaitForInputIdle(10000)) // 10 s timout
throw new ApplicationException("Process takes too much time to start");
_hWnd = net4ReconProcess.MainWindowHandle;

Application.Current.Shutdown() doesn't

Title's about it. WPF app with some WCF stuff for IPC. I call Application.Current.Shutdown() and the app continues on happily. I thought Shutdown was supposed to be unstoppable.
Perhaps because it's being called from a background thread? Do I need to do some dispatcher fiddling?
You get an exception when I call Application.Current.Shutdown in any thread other than the main one, so I'd assume you where using "dispatcher fiddling" properly already.
In any case, this compiles and quits an application, so if the dispatcher bit doesn't look like what you have you could sling it in:
ThreadStart ts = delegate()
{
Dispatcher.BeginInvoke((Action)delegate()
{
Application.Current.Shutdown();
});
};
Thread t = new Thread(ts);
t.Start();
In my experience all threads have to either be terminated explicitly or be marked as background threads in order for the application to close.
Here is an example of kicking off a read thread in the background:
_readThread = new Thread(new ThreadStart(ReadThread));
_readThread.Name = "Receiver";
_readThread.Priority = ThreadPriority.Highest;
_readThread.IsBackground = true;
_readThread.Start();
The IsBackground property is the key. Without that being set, the thread won't terminate on when you call Shutdown.
I only experience Application.Current.Shutdown not working when I'm running from Visual Studio. Within Visual Studio (at least the 2010 version I'm using) Application.Current.Shutdown doesn't do a thing. If I single step through it executes this line and then continues. If I run the program (as an .exe) from Windows Explorer then Application.Current.Shutdown works fine.
There is probably an explanation for this since during debug other threads are active, but I can't explain it.

Resources