Trying to pause and restart a process from Max using aka.shell – format issue?

Feb 5, 2011 at 3:32am

Trying to pause and restart a process from Max using aka.shell – format issue?

Hi guys,
I am having what must be formatting issues with aka.shell. I am trying to pause and resume a Max runtime app from another Max runtime app. I don’t want to kill the process entirely and reopen the app, I’ve gotten that to work with the kill command to aka.shell. Instead, I’m trying to query for the PID using, then send the kill message with a flag to aka.shell when the app is not in use:
kill -SIGSTOP [PID#]
Then I want to restart the process with:
kill -SIGCONT [PID#]
These messages work just fine from the terminal, but aka.shell just gives me a “no result” error message.
I have attached both a patch and a simple test app to easily reproduce the problem – just unzip the folder and launch the file “pauseprocess.maxpat” (there are instructions in comments) then launch TESTAPP from the finder and turn on the audio.

TESTAPP is just a bunch of copies of the filtergraph help file all connected to an ezdac with the volume turned down. It’s meant to just do some dsp and show up in the activity monitor eating around 9% of cpu – this way you can see the difference when the process is successfully paused.

I’ve been playing around with quotes, the symout argument in sprintf… am I missing a backslash somewhere? I think I’m just doing the flag wrong somehow because the kill command by itself works from max for me. I’m on a MacBook Pro, OSX 10.6.3 running Max 5.1.4 [42462] – though incidentally it would be great to find a solution that works for windows too. Thanks so much for any suggestions.
-Diane

#54810
Feb 5, 2011 at 3:37am

Sorry, my attachment didn’t work in my last post. Trying again…

#197342
Feb 5, 2011 at 3:50am

ok it looks like that one didn’t work either. Here, at least, is the patch. Just pick an application that eats some cpu and type it into the message box at the top where it says TESTAPP. thanks!
-diane

– Pasted Max Patch, click to expand. –
#197343
Feb 5, 2011 at 11:14pm

Hi again forum,
Sorry to post again but I’m getting desperate!
I tried both shell and aka.shell with the same result.
kill [PID] from max works just fine with both, but the flag -SIGSTOP is not understood. This works fine in the terminal, but I can’t figure out why it doesn’t work from max! Please help, I’m so close… but I’ve put in so many hours on researching this – I’ve scoured the forums, google, applescript docs, unix commandline docs, the cycling docs, any examples of aka.shell or shell i could find, direct ;max messages, regexp and sprintf docs, ANY SUGGESTIONS AT ALL VERY WELCOME, at this point they could involve dark magic and I would be fine with that:)
All I want to do is pause and restart a process on the OS level without killing it entirely.

#197344
Feb 6, 2011 at 2:03am

it worked for me with shell object when instead of using the signal symbol, i used the signal number.
i had to find the signal.h header file, which lists the numbers.
on snow leopard, stop is 17 and cont is 19:
kill -17 16248

#197345
Feb 6, 2011 at 3:44am

Hi Robert! THANKS SO MUCH! I don’t use all caps lightly. I’ve spent the last 3 days/nights trying to figure this one out. That worked great, and if anyone else needs it I’m including the patch at the bottom of this post. Just one other question though, I couldn’t figure out how you got those numbers 17 and 19. I found 3 copies of signal.h on my computer and they didn’t seem to list commands – though maybe I’m not reading it right? I only ask because I’m trying to make this program extremely portable. Since other people will be running different OS versions etc, will this same trick work? or will I have to somehow query their signal.h file from my program? Here is what mine looks like:

/*
* Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the ‘License’). You may not use this file except in
* compliance with the License. The rights granted to you under the License
* may not be used to create, or enable the creation or redistribution of,
* unlawful or unlicensed copies of an Apple operating system, or to
* circumvent, violate, or enable the circumvention or violation of, any
* terms of an Apple operating system software license agreement.
*
* Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this file.
*
* The Original Code and all software distributed under the License are
* distributed on an ‘AS IS’ basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_END@
*/
/*
* Copyright (c) 1992 NeXT Computer, Inc.
*
*/

#ifndef _I386_SIGNAL_H_
#define _I386_SIGNAL_H_ 1

#include

#ifndef _ANSI_SOURCE
typedef int sig_atomic_t;

#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)

#include

#ifdef __APPLE_API_OBSOLETE

/*
* Information pushed on stack when a signal is delivered.
* This is used by the kernel to restore state following
* execution of the signal handler. It is also made available
* to the handler to allow it to properly restore state if
* a non-standard exit is performed.
*/
#define __need_struct_sigcontext
#include

#endif /* __APPLE_API_OBSOLETE */
#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
#endif /* ! _ANSI_SOURCE */

#endif /* _I386_SIGNAL_H_ */

Anyway, thanks so much again for your help. it was just what I needed!
-Diane
And here is the patch that worked:

– Pasted Max Patch, click to expand. –
#197346
Feb 7, 2011 at 4:48pm

yeah, i’m not sure how portable this solution is.
the signal.h file that lists the values is actually from the Developer SDK. you would have to install the xcode developer tools to have access to that.

but since this would only work on mac anyways, maybe the codes stay consistent.

#197347

You must be logged in to reply to this topic.