Exemplo n.º 1
0
static int try_kill_one()
{
    /* Only need to check if a timeout was specified with the -l option. */
    if ( globs.timeout > 0 )
    {
        int i;
        for ( i = 0; i < globs.jobs; ++i )
            if ( cmdtab[ i ].pi.hProcess )
            {
                double const t = running_time( cmdtab[ i ].pi.hProcess );
                if ( t > (double)globs.timeout )
                {
                    /* The job may have left an alert dialog around, try and get
                     * rid of it before killing the job itself.
                     */
                    close_alert( &cmdtab[ i ].pi );
                    /* We have a "runaway" job, kill it. */
                    kill_process_tree( cmdtab[ i ].pi.dwProcessId,
                        cmdtab[ i ].pi.hProcess );
                    /* And return its running commands table slot. */
                    return i;
                }
            }
    }
    return -1;
}
Exemplo n.º 2
0
Arquivo: execnt.c Projeto: 4ukuta/core
static int try_kill_one()
{
    /* Only need to check if a timeout was specified with the -l option. */
    if ( globs.timeout > 0 )
    {
        int i;
        for ( i = 0; i < globs.jobs; ++i )
        {
            double t = running_time( cmdtab[ i ].pi.hProcess );
            if ( t > (double)globs.timeout )
            {
                /* The job may have left an alert dialog around, try and get rid
                 * of it before killing
                 */
                close_alert( cmdtab[ i ].pi.hProcess );
                /* We have a "runaway" job, kill it. */
                kill_process_tree( 0, cmdtab[ i ].pi.hProcess );
                /* And return it marked as a timeout. */
                cmdtab[ i ].exit_reason = EXIT_TIMEOUT;
                return i;
            }
        }
    }
    return -1;
}
Exemplo n.º 3
0
cv::Mat1b GraphSeg::execute(const multi_img& input,
                                  const cv::Mat1b& seeds,
                                  cv::Mat1b *proba_map) {
	Stopwatch running_time("Total Running Time");
	cv::Mat1b output;
	int i;

	if ((seeds.cols != input.width)||(seeds.rows != input.height)) {
		std::cerr << "ERROR: Seed file dimensions do not match image dimensions!"
		          << std::endl;
		return output; // which is empty so far
	}

	Graph graph(seeds.cols, seeds.rows);

	/* extract seeds */
	cv::Mat1b::const_iterator it;
	if (config.multi_seed == true) {		// multilabel seed image
		graph.max_label = 0;
		for (i = 0, it = seeds.begin(); it < seeds.end(); ++i, ++it) {
			if (*it > 0) {
				graph.seeds.push_back(std::make_pair(i, *it));
				if (*it > graph.max_label)
					graph.max_label = *it;
			}
		}
	} else {
		graph.max_label = 2;
		for (i = 0, it = seeds.begin(); it < seeds.end(); ++i, ++it) {
			if (*it > 192) {
				graph.seeds.push_back(std::make_pair(i, 1));
			} else if (*it < 64) {
				graph.seeds.push_back(std::make_pair(i, 2));
			}
		}
	}

	// edge weights
	similarity_measures::SimilarityMeasure<multi_img::Value> *distfun;
#ifdef WITH_SOM
	boost::shared_ptr<som::GenSOM> som; // create in this scope for survival
	if (!config.som_similarity) {
		distfun = similarity_measures::SMFactory<multi_img::Value>
				::spawn(config.similarity);
	} else {
		input.rebuildPixels();
		som = boost::shared_ptr<som::GenSOM>(
					som::GenSOM::create(config.som, input));
		distfun = new som::SOMDistance<multi_img::Value>(*som, input);
	}
#else
	distfun = SMFactory<multi_img::Value>::spawn(config.similarity);
#endif

	assert(distfun);

	Stopwatch watch;
	if (config.algo == WATERSHED2) {
		/* Kruskal & RW on plateaus multiseeds linear time */

		graph.color_standard_weights(input, distfun, true);
		watch.print_reset("Graph coloring");
		// for PW, color_standard_weights is always called with geodesic = true
		output = graph.PowerWatershed_q2(config.geodesic, proba_map);
		watch.print("Segmentation");
	} else {
		graph.color_standard_weights(input, distfun, config.geodesic);
		watch.print_reset("Graph coloring");
		if (config.algo == KRUSKAL) { // Kruskal
			output = graph.MSF_Kruskal();
		} else if (config.algo == PRIM) { // Prim RB tree
			output = graph.MSF_Prim();
		}
		watch.print("Segmentation");
	}

	delete distfun;

	return output;
}
Exemplo n.º 4
0
static int
my_wait( int *status )
{
	int i, num_active = 0;
	DWORD exitcode, waitcode;
	HANDLE active_handles[MAXJOBS];

	/* first see if any non-waited-for processes are dead,
	 * and return if so.
	 */
	for ( i = 0; i < globs.jobs; i++ )
    {
        int pid = cmdtab[i].pid;
        
	    if ( pid )
        {
            process_state state
                = check_process_exit((HANDLE)pid, status, active_handles, &num_active);
            
            if ( state == process_error )
                goto FAILED;
            else if ( state == process_finished )
                return pid;
	    }
	}

	/* if a child exists, wait for it to die */
	if ( !num_active )
    {
	    errno = ECHILD;
	    return -1;
	}
    
    if ( globs.timeout > 0 )
    {
        unsigned int alert_wait = 1;
        /* with a timeout we wait for a finish or a timeout, we check every second
         to see if something timed out */
        for (waitcode = WAIT_TIMEOUT; waitcode == WAIT_TIMEOUT; ++alert_wait)
        {
            waitcode = WaitForMultipleObjects( num_active, active_handles, FALSE, 1*1000 /* 1 second */ );
            if ( waitcode == WAIT_TIMEOUT )
            {
                /* check if any jobs have surpassed the maximum run time. */
                for ( i = 0; i < num_active; ++i )
                {
                    double t = running_time(active_handles[i]);

                    /* periodically (each 5 secs) check and close message boxes
                    displayed by any of our child processes */
                    if ((alert_wait % ((unsigned int) 5)) == 0)
                        close_alert(active_handles[i]);

                    if ( t > (double)globs.timeout )
                    {
                        /* the job may have left an alert dialog around,
                        try and get rid of it before killing */
                        close_alert(active_handles[i]);
                        /* we have a "runaway" job, kill it */
                        kill_all(0,active_handles[i]);
                        /* indicate the job "finished" so we query its status below */
                        waitcode = WAIT_ABANDONED_0+i;
                    }
                }
            }
        }
    }
    else
    {
        /* no timeout, so just wait indefinately for something to finish */
        waitcode = WaitForMultipleObjects( num_active, active_handles, FALSE, INFINITE );
    }
	if ( waitcode != WAIT_FAILED )
    {
	    if ( waitcode >= WAIT_ABANDONED_0
             && waitcode < WAIT_ABANDONED_0 + num_active )
            i = waitcode - WAIT_ABANDONED_0;
	    else
            i = waitcode - WAIT_OBJECT_0;
        
        if ( check_process_exit(active_handles[i], status, 0, 0) == process_finished )
            return (int)active_handles[i];
	}

FAILED:
	errno = GetLastError();
	return -1;
    
}