Como lançar «gdbserver» em segundo plano?

1

Estou me comunicando com um dispositivo através de uma porta serial, e para isso eu sou lançado «gdbserver» (como gdbserver :2345 myapp ) bloqueia completamente o terminal. Nem um símbolo% amperes & nem uma combinação ^ z puderam enviá-lo para um segundo plano. Também acabei de verificar: o «gdbserver» também se comporta dessa maneira no Kubuntu.

Eu realmente preciso usar um comando shell e, como eu não tenho idéia de como executar isso via "gdbserver», depois que eu lancei eu me sinto aleijado.

    
por Hi-Angel 05.11.2014 / 15:16

2 respostas

3

Isso parece ter funcionado para o OP.

gdbserver :2345 ls > /dev/null 2>&1 &

Eu acho que a razão para isso é porque quando um programa é daemonizado, ele fecha todos os STDIO 0,1 & 2. O próximo IO a ser aberto será 0. Se o programa tentar usar 0,1 ou 2 com elementos como printf ou scanf, ele estará atuando no IO errado ou em um IO fechado. Por exemplo, se ele é daemonizado, o soquete se abre em 0 se STDIN estava e, se o printf for chamado, ele estará gravando em um FD não aberto, o que causaria a falha do programa.

    
por 05.11.2014 / 19:32
2

Eu nunca encontrei uma maneira de realmente desembaraçar com um shell, existem muitas razões pelas quais algo permanecerá conectado. Eu escrevi um programa C muito pequeno para separar todos os comandos que você executa depois dele. Espero que isso ajude você.

----- daemonize.c

#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <syslog.h>
#include <string.h>

int main(int argc, char *argv[]) {
    int i;
    // int reterr;
    pid_t pid, sid;

    //Fork the Parent Process
    pid = fork();

    if (pid < 0) { exit(EXIT_FAILURE); }

    //We got a good pid, Close the Parent Process
    if (pid > 0) { exit(EXIT_SUCCESS); }

    //Change File Mask
    umask(0);

    //Create a new Signature Id for our child
    sid = setsid();
    if (sid < 0) { exit(EXIT_FAILURE); }

    //Change Directory
    //If we cant find the directory we exit with failure.
    if ((chdir("/")) < 0) { exit(EXIT_FAILURE); }

    //Close Standard File Descriptors
    close(STDIN_FILENO);
    close(STDOUT_FILENO);
    close(STDERR_FILENO);

    //----------------
    //Main Process
    //----------------
    for(i=0; i < argc - 1; i++) {
        argv[i]=argv[i+1];
    }
    argv[argc-1] = '
CXX = gcc

# Implicit rules needed to build .o files and Metaobject stuff (_m.o)
.SUFFIXES: .c .o .h

.c.o:
    $(CXX) -c $(XTRA_INCL)   $< -o $@

OBJECTS = daemonize.o 
daemonize: $(OBJECTS)
    $(CXX) -o $@ -pipe -O2 $(OBJECTS) $(RPATH_XT)
    strip --strip-unneeded $@

clean:
    @rm -f core *.o *_m.* *.bak *.elf
'; execv(argv[0], argv); //reterr = execv(argv[0], argv); //printf("execv failed with '%s'\n", strerror(errno)); //Close the log closelog (); }

--- Makefile

#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <syslog.h>
#include <string.h>

int main(int argc, char *argv[]) {
    int i;
    // int reterr;
    pid_t pid, sid;

    //Fork the Parent Process
    pid = fork();

    if (pid < 0) { exit(EXIT_FAILURE); }

    //We got a good pid, Close the Parent Process
    if (pid > 0) { exit(EXIT_SUCCESS); }

    //Change File Mask
    umask(0);

    //Create a new Signature Id for our child
    sid = setsid();
    if (sid < 0) { exit(EXIT_FAILURE); }

    //Change Directory
    //If we cant find the directory we exit with failure.
    if ((chdir("/")) < 0) { exit(EXIT_FAILURE); }

    //Close Standard File Descriptors
    close(STDIN_FILENO);
    close(STDOUT_FILENO);
    close(STDERR_FILENO);

    //----------------
    //Main Process
    //----------------
    for(i=0; i < argc - 1; i++) {
        argv[i]=argv[i+1];
    }
    argv[argc-1] = '
CXX = gcc

# Implicit rules needed to build .o files and Metaobject stuff (_m.o)
.SUFFIXES: .c .o .h

.c.o:
    $(CXX) -c $(XTRA_INCL)   $< -o $@

OBJECTS = daemonize.o 
daemonize: $(OBJECTS)
    $(CXX) -o $@ -pipe -O2 $(OBJECTS) $(RPATH_XT)
    strip --strip-unneeded $@

clean:
    @rm -f core *.o *_m.* *.bak *.elf
'; execv(argv[0], argv); //reterr = execv(argv[0], argv); //printf("execv failed with '%s'\n", strerror(errno)); //Close the log closelog (); }
    
por 05.11.2014 / 15:39