Inter-process communication

RSS for tag

Share data through Handoff, support universal links to your app's content, and display activity-based services to the user using inter-process communication.

Posts under Inter-process communication tag

88 Posts

Post

Replies

Boosts

Views

Activity

Why is applicationDidFinishLaunching not called when using an ssh connection to the MacOS machine
Hello, We created a sample app delegate to test whether applicationDidFinishLaunching runs as expected or not (code as follows). The observed behavior was that the executable prints both applicationWillFinishLaunching and applicationDidFinishLaunching in the case when we're using an RDP connection to the mac prints only applicationWillFinishLaunching in case of ssh connection to the mac Why is this behavior different and how can I ensure it runs correctly with ssh? Kindly help. #include <unistd.h> #include <sys/types.h> #include <Foundation/Foundation.h> #import <Cocoa/Cocoa.h> #import <SystemConfiguration/SystemConfiguration.h> #import <SystemConfiguration/SCDynamicStore.h> @interface TWAppKitAppDelegate : NSObject <NSApplicationDelegate> @end @implementation TWAppKitAppDelegate // Launching Applications - (void) applicationWillFinishLaunching: (NSNotification *) pNotification { NSLog(@"applicationWillFinishLaunching"); } - (void) applicationDidFinishLaunching: (NSNotification *) pNotification { NSLog(@"applicationDidFinishLaunching"); } // Managing Active Status - (void) applicationWillBecomeActive: (NSNotification *) pNotification { } - (void) applicationDidBecomeActive: (NSNotification *) pNotification { } - (void) applicationWillResignActive: (NSNotification *) pNotification { } - (void) applicationDidResignActive: (NSNotification *) pNotification { } // Terminating Applications #if 0 - (NSApplicationTerminateReply) applicationShouldTerminate:(NSNotification *) pNotification { return NSApplicationTerminateReply::NSTerminateNow; } #endif - (BOOL) applicationShouldTerminateAfterLastWindowClosed:(NSNotification *) pNotification { return NO; } - (void) applicationWillTerminate:(NSNotification *) pNotification { } - (BOOL) application:(NSApplication *) pSender openFile: (NSString *) pFileName { return YES; } - (void) application:(NSApplication *) pSender openFiles: (NSArray<NSString *> *) pFileNames { } @end int main (int pArgc, char ** pArgv) { NSApplication * app; TWAppKitAppDelegate * appdelegate; app = [NSApplication sharedApplication]; appdelegate = [[TWAppKitAppDelegate alloc] init]; [app setDelegate:appdelegate]; [NSApp run]; //NOTE: Apple never 'returns' from here NSLog(@"Function main called \n"); return 0; }
1
0
1.3k
Oct ’21
Shared-memory pthread condition variable not working
I’m trying to implement a simple cross-process notify/observe system, using a pthread mutex and condition variable in shared (mapped) memory. It seems to be working fine (on macOS 11.6) if one process calls pthread_cond_wait and then another calls pthread_cond_broadcast — the waiting process indeed wakes up. However, if two processes try to observe at the same time, the second one's call to pthread_cond_wait fails with EINVAL. I’m wondering if I’m just doing something wrong in my setup, or if this sort of usage isn’t supported. Basically I create and mmap a file, initialize a pthread mutex and condition in the mapped memory using the setpshared attributes, then lock the mutex and notify or wait on the condition. Actual source code here: Here’s the code that does the pthreads stuff Here’s the outer code that opens and mmaps the file I’m aware that there are a few dozen 🙄 Apple IPC APIs that are probably preferred over these POSIX ones. I’ve used some in the past. I’m doing it this way because: (a) this is in a cross-platform project and it would be nice to share code between Unix platforms, at least Darwin and Linux; (b) the thing I’m notifying/observing about is a database file, so tying the notifications to a side file next to the database provides ideal scoping; (c) it’s similar in principle to the usage of shared memory for locking in SQLite and LMDB. (The difference is, I’m doing notification not locking.) Any advice? —Jens
1
1
1.3k
Oct ’21
Setting shared memory in Catalina
I have written C software that makes extensive use of shared memory (200MB using shmget, etc.), which compiled and ran on Mojave and Linux. Using this shared memory required /etc/sysctl.conf to increase the buffer sizes during OSX boot. It appears that Catalina no longer uses my /etc/sysctl.conf file, whether SIP is enabled or disabled. Now the software compiles but fails to run, because the default shared memory size (4MB) is too small on Catalina. How do I specify the shared memory parameters to increase above the default in Catalina? kern.sysv.shmmax=268435456 kern.sysv.shmmin=1 #kern.sysv.shmmni=128 kern.sysv.shmseg=32 kern.sysv.shmall=65536
4
0
5.2k
Oct ’21
swift Process() return values
How do I access a returned value from a Process(), in this case 'which'... var sips_path : String? //MARK: locate sips on local machine let which_sips = Process() which_sips.executableURL = URL(fileURLWithPath: "which") which_sips.arguments = ["sips"] do { sips_path = try which_sips.run() } catch let error as NSError { sips_path = "/usr/bin/sips"; print("Failed to execute which_sips", error) }line 8. gets compiler error "Cannot assign value of type '()' to type 'String?'" I believe, but cannot prove, 'which' returns a string. .run() throws and throws are for errors only, right? So where is the result of calling which?It seems I should use a closure to use $0 but it's already in one...line 9. intends to assign a default path.
13
1
8.0k
Oct ’21
XPC so universal app can interact with ARM or Intel dylib?
Hello - TLDR - Is there any sample code to demonstrate how one goes about creating dedicated XPCServices to wrap ARM and Intel-specific dylibs? We have an app we're looking at moving to a universal binary. In that same app we have a framework that currently wraps R functionality by directly linking to /Library/Frameworks/R.framework/Current . R now has dedicated Intel and ARM builds (https://mac.r-project.org/) After watching the 2020 WWDC session "Port your Mac app to Apple silicon" (https://developer.apple.com/videos/play/wwdc2020/10214/?time=2006), it sounds like, for us to deploy a universal binary I should look at wrapping the R interaction bits into dedicated ARM and Intel XPC services so the appropriate architecture for R will run. Is anyone aware of any sample code or extended documentation demonstrating the ins and outs of how to think about this? Thank you
9
0
2.5k
Sep ’21
Returning values from terminal
I'm opening a different thread to a question that was asked about a year ago. I'm trying to get the output of "which" so that I can automatically find programs for the user. I've used the code that was provided in that thread which is:  func launch(tool: URL, arguments: [String], completionHandler: @escaping (Int32, Data) -> Void) throws {         let group = DispatchGroup()         let pipe = Pipe()         var standardOutData = Data()         group.enter()         let proc = Process()         proc.executableURL = tool         proc.arguments = arguments         proc.standardOutput = pipe.fileHandleForWriting         proc.terminationHandler = { _ in             proc.terminationHandler = nil             group.leave()         }         group.enter()         DispatchQueue.global().async {             // Doing long-running synchronous I/O on a global concurrent queue block             // is less than ideal, but I’ve convinced myself that it’s acceptable             // given the target ‘market’ for this code.             let data = pipe.fileHandleForReading.readDataToEndOfFile()             pipe.fileHandleForReading.closeFile()             DispatchQueue.main.async {                 standardOutData = data                 group.leave()             }         }         group.notify(queue: .main) {             completionHandler(proc.terminationStatus, standardOutData)         }         try proc.run()         // We have to close our reference to the write side of the pipe so that the         // termination of the child process triggers EOF on the read side.         pipe.fileHandleForWriting.closeFile()     } it works fine for all of the normal command line routines but not for custom ones such as avr-gcc or any other that is installed via homebrew. I can use "which avr-gcc" in terminal and it shows the path just fine but in my app it returns nothing where as if I search for the path of something like ls in my app it returns it just fine. What could be the cause of this?
3
0
1.3k
Sep ’21
launchDaemon choose shared file location that doesn't require full disk access
I've got an mach-o executable that runs from launchDaemon plist file, and is communicating with other processes using unix domain socket. The file that backs this socket created in /tmp. However, this cause the executable to fail reading the file unless given full disk access. I'd like to find a location for the socket file, which is shared to all processes and doesn't require full disk access. the executable reside in /Library/Application Support/myProj/bin/exec_file is there such location ? Perhaps can i use the same location of the executable itself ?
2
0
974
Sep ’21
BSD Socket TCP Server in background : swift with C++
Hi All, I have coded a TCP Server packaged inside C++ static library. I am using this static library within the iOS Swift UI application. I have coded a simple UI which has a button, on click of which I want to start the TCP server (which is written in C++ and inside the linked static library). After the TCP server is started, I want to push the application to background and then run the client application which is going to interact with this TCP server from the backgrounded SwiftUI application. I want the TCP server to be running even the application goes to the background mode as I have another user interface application which is going to interact with the TCP server on the same device. I tried using background task, but I don't know whether I am doing something wrong there, or I cannot achieve what I want using the BackgroundTask functionality available in iOS. The main thing here is, the TCP server code is in C++ inside static library and I want to start the TCP server from SwiftUI application layer. I have managed to call C++ function from Swift that part is available. Can anyone show me the right path here ? How do I keep the BSD Socket based TCP Server active while the application is in Background mode ?
11
0
2.2k
Aug ’21
Why is applicationDidFinishLaunching not called when using an ssh connection to the MacOS machine
Hello, We created a sample app delegate to test whether applicationDidFinishLaunching runs as expected or not (code as follows). The observed behavior was that the executable prints both applicationWillFinishLaunching and applicationDidFinishLaunching in the case when we're using an RDP connection to the mac prints only applicationWillFinishLaunching in case of ssh connection to the mac Why is this behavior different and how can I ensure it runs correctly with ssh? Kindly help. #include <unistd.h> #include <sys/types.h> #include <Foundation/Foundation.h> #import <Cocoa/Cocoa.h> #import <SystemConfiguration/SystemConfiguration.h> #import <SystemConfiguration/SCDynamicStore.h> @interface TWAppKitAppDelegate : NSObject <NSApplicationDelegate> @end @implementation TWAppKitAppDelegate // Launching Applications - (void) applicationWillFinishLaunching: (NSNotification *) pNotification { NSLog(@"applicationWillFinishLaunching"); } - (void) applicationDidFinishLaunching: (NSNotification *) pNotification { NSLog(@"applicationDidFinishLaunching"); } // Managing Active Status - (void) applicationWillBecomeActive: (NSNotification *) pNotification { } - (void) applicationDidBecomeActive: (NSNotification *) pNotification { } - (void) applicationWillResignActive: (NSNotification *) pNotification { } - (void) applicationDidResignActive: (NSNotification *) pNotification { } // Terminating Applications #if 0 - (NSApplicationTerminateReply) applicationShouldTerminate:(NSNotification *) pNotification { return NSApplicationTerminateReply::NSTerminateNow; } #endif - (BOOL) applicationShouldTerminateAfterLastWindowClosed:(NSNotification *) pNotification { return NO; } - (void) applicationWillTerminate:(NSNotification *) pNotification { } - (BOOL) application:(NSApplication *) pSender openFile: (NSString *) pFileName { return YES; } - (void) application:(NSApplication *) pSender openFiles: (NSArray<NSString *> *) pFileNames { } @end int main (int pArgc, char ** pArgv) { NSApplication * app; TWAppKitAppDelegate * appdelegate; app = [NSApplication sharedApplication]; appdelegate = [[TWAppKitAppDelegate alloc] init]; [app setDelegate:appdelegate]; [NSApp run]; //NOTE: Apple never 'returns' from here NSLog(@"Function main called \n"); return 0; }
Replies
1
Boosts
0
Views
1.3k
Activity
Oct ’21
Shared-memory pthread condition variable not working
I’m trying to implement a simple cross-process notify/observe system, using a pthread mutex and condition variable in shared (mapped) memory. It seems to be working fine (on macOS 11.6) if one process calls pthread_cond_wait and then another calls pthread_cond_broadcast — the waiting process indeed wakes up. However, if two processes try to observe at the same time, the second one's call to pthread_cond_wait fails with EINVAL. I’m wondering if I’m just doing something wrong in my setup, or if this sort of usage isn’t supported. Basically I create and mmap a file, initialize a pthread mutex and condition in the mapped memory using the setpshared attributes, then lock the mutex and notify or wait on the condition. Actual source code here: Here’s the code that does the pthreads stuff Here’s the outer code that opens and mmaps the file I’m aware that there are a few dozen 🙄 Apple IPC APIs that are probably preferred over these POSIX ones. I’ve used some in the past. I’m doing it this way because: (a) this is in a cross-platform project and it would be nice to share code between Unix platforms, at least Darwin and Linux; (b) the thing I’m notifying/observing about is a database file, so tying the notifications to a side file next to the database provides ideal scoping; (c) it’s similar in principle to the usage of shared memory for locking in SQLite and LMDB. (The difference is, I’m doing notification not locking.) Any advice? —Jens
Replies
1
Boosts
1
Views
1.3k
Activity
Oct ’21
Setting shared memory in Catalina
I have written C software that makes extensive use of shared memory (200MB using shmget, etc.), which compiled and ran on Mojave and Linux. Using this shared memory required /etc/sysctl.conf to increase the buffer sizes during OSX boot. It appears that Catalina no longer uses my /etc/sysctl.conf file, whether SIP is enabled or disabled. Now the software compiles but fails to run, because the default shared memory size (4MB) is too small on Catalina. How do I specify the shared memory parameters to increase above the default in Catalina? kern.sysv.shmmax=268435456 kern.sysv.shmmin=1 #kern.sysv.shmmni=128 kern.sysv.shmseg=32 kern.sysv.shmall=65536
Replies
4
Boosts
0
Views
5.2k
Activity
Oct ’21
swift Process() return values
How do I access a returned value from a Process(), in this case 'which'... var sips_path : String? //MARK: locate sips on local machine let which_sips = Process() which_sips.executableURL = URL(fileURLWithPath: "which") which_sips.arguments = ["sips"] do { sips_path = try which_sips.run() } catch let error as NSError { sips_path = "/usr/bin/sips"; print("Failed to execute which_sips", error) }line 8. gets compiler error "Cannot assign value of type '()' to type 'String?'" I believe, but cannot prove, 'which' returns a string. .run() throws and throws are for errors only, right? So where is the result of calling which?It seems I should use a closure to use $0 but it's already in one...line 9. intends to assign a default path.
Replies
13
Boosts
1
Views
8.0k
Activity
Oct ’21
XPC so universal app can interact with ARM or Intel dylib?
Hello - TLDR - Is there any sample code to demonstrate how one goes about creating dedicated XPCServices to wrap ARM and Intel-specific dylibs? We have an app we're looking at moving to a universal binary. In that same app we have a framework that currently wraps R functionality by directly linking to /Library/Frameworks/R.framework/Current . R now has dedicated Intel and ARM builds (https://mac.r-project.org/) After watching the 2020 WWDC session "Port your Mac app to Apple silicon" (https://developer.apple.com/videos/play/wwdc2020/10214/?time=2006), it sounds like, for us to deploy a universal binary I should look at wrapping the R interaction bits into dedicated ARM and Intel XPC services so the appropriate architecture for R will run. Is anyone aware of any sample code or extended documentation demonstrating the ins and outs of how to think about this? Thank you
Replies
9
Boosts
0
Views
2.5k
Activity
Sep ’21
Returning values from terminal
I'm opening a different thread to a question that was asked about a year ago. I'm trying to get the output of "which" so that I can automatically find programs for the user. I've used the code that was provided in that thread which is:  func launch(tool: URL, arguments: [String], completionHandler: @escaping (Int32, Data) -> Void) throws {         let group = DispatchGroup()         let pipe = Pipe()         var standardOutData = Data()         group.enter()         let proc = Process()         proc.executableURL = tool         proc.arguments = arguments         proc.standardOutput = pipe.fileHandleForWriting         proc.terminationHandler = { _ in             proc.terminationHandler = nil             group.leave()         }         group.enter()         DispatchQueue.global().async {             // Doing long-running synchronous I/O on a global concurrent queue block             // is less than ideal, but I’ve convinced myself that it’s acceptable             // given the target ‘market’ for this code.             let data = pipe.fileHandleForReading.readDataToEndOfFile()             pipe.fileHandleForReading.closeFile()             DispatchQueue.main.async {                 standardOutData = data                 group.leave()             }         }         group.notify(queue: .main) {             completionHandler(proc.terminationStatus, standardOutData)         }         try proc.run()         // We have to close our reference to the write side of the pipe so that the         // termination of the child process triggers EOF on the read side.         pipe.fileHandleForWriting.closeFile()     } it works fine for all of the normal command line routines but not for custom ones such as avr-gcc or any other that is installed via homebrew. I can use "which avr-gcc" in terminal and it shows the path just fine but in my app it returns nothing where as if I search for the path of something like ls in my app it returns it just fine. What could be the cause of this?
Replies
3
Boosts
0
Views
1.3k
Activity
Sep ’21
launchDaemon choose shared file location that doesn't require full disk access
I've got an mach-o executable that runs from launchDaemon plist file, and is communicating with other processes using unix domain socket. The file that backs this socket created in /tmp. However, this cause the executable to fail reading the file unless given full disk access. I'd like to find a location for the socket file, which is shared to all processes and doesn't require full disk access. the executable reside in /Library/Application Support/myProj/bin/exec_file is there such location ? Perhaps can i use the same location of the executable itself ?
Replies
2
Boosts
0
Views
974
Activity
Sep ’21
BSD Socket TCP Server in background : swift with C++
Hi All, I have coded a TCP Server packaged inside C++ static library. I am using this static library within the iOS Swift UI application. I have coded a simple UI which has a button, on click of which I want to start the TCP server (which is written in C++ and inside the linked static library). After the TCP server is started, I want to push the application to background and then run the client application which is going to interact with this TCP server from the backgrounded SwiftUI application. I want the TCP server to be running even the application goes to the background mode as I have another user interface application which is going to interact with the TCP server on the same device. I tried using background task, but I don't know whether I am doing something wrong there, or I cannot achieve what I want using the BackgroundTask functionality available in iOS. The main thing here is, the TCP server code is in C++ inside static library and I want to start the TCP server from SwiftUI application layer. I have managed to call C++ function from Swift that part is available. Can anyone show me the right path here ? How do I keep the BSD Socket based TCP Server active while the application is in Background mode ?
Replies
11
Boosts
0
Views
2.2k
Activity
Aug ’21