Home
Support

Knowledge Base

BSPs and drivers
Community resources
Product documentation
Questions?
Contact us

How to wait on the death of a process
 
________________________________________________________________________

Applicable Environment
________________________________________________________________________
  • Topic: Wait on death of process
  • SDP: 6.4.1
  • Target: Any supported target
________________________________________________________________________

Recommendation
________________________________________________________________________

Sample code:

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <err.h>
#include <fcntl.h>
#include <sys/procfs.h>


static char *whys[] = {
"REQUESTED",
"SIGNALLED",
"FAULTED",
"JOBCONTROL",
"TERMINATED",
"CHILD",
"EXEC"
};

int main( int argc, char *argv[] ) {
procfs_status status;
procfs_run run;
pid_t pid = strtoul( argv[1], NULL, 0 );
char path[50];
int fd;

sprintf( path, "/proc/%d/as", pid );

if ( -1 == ( fd = open( path, O_RDWR ) ) )
err( EXIT_FAILURE, "open(%s)", path );

memset( &run, 0, sizeof run );

if ( EOK != ( errno = devctl( fd, DCMD_PROC_WAITSTOP, &status, sizeof status, NULL ) ) )
err( EXIT_FAILURE, "devctl(%s,DCMD_PROC_WAITSTOP)", path );

close( fd );
printf( "%d exited. Why=%x (%s)\n", pid, status.why, whys[status.why] );

return EXIT_SUCCESS;
}

________________________________________________________________________
NOTE: This entry has been validated against the SDP version listed above. Use caution when considering this advice for any other SDP version. For supported releases, please reach out to QNX Technical Support if you have any questions/concerns.
________________________________________________________________________


Related Attachments
 None Found





Please contact us with your questions or concerns.