Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

688
Visualizações
Alternative of system() in c Linux to execute a terminal command on linux

I want to execute a terminal command of Linux in a C program. Currently I am using system() function but I want to use any other as the system() function is banned as per MISRA.

For example, how can I replace

 system("hwclock --systohc --utc");
over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

First you can use fork()to create a child process,then in the child process,you can call exec() to execute command what you want.
There is a simple example:

$ chmod u+x command.sh 
$ cat command.sh  

#!/usr/bin/env bash
ls -l

************* test.c ****************

#include<unistd.h>
int main(void)
{
  execl("./command.sh","command.sh",(char*)0);
  return 0;
}
over 4 years ago · Santiago Trujillo Relatório

0

You can make use of fork() and then look up for exec() family of functions.

Alternatively, you may want to have a look at popen() also.

over 4 years ago · Santiago Trujillo Relatório

0

This is a very interesting question. My understanding of MISRA C is that it provides guidelines for the use of the C language in critical systems. But the C language standard library, which includes the system function, is merely a small piece of the sum total of library code typically used in modern applications -- often even in embedded systems.

I've never developed an application to MISRA standards, and I've only been able to find a slightly older (from 2004) version of the MISRA guidelines. From what I can tell, MISRA is silent about the use of POSIX library functions, which you are typically going to have available on any kind of Linux-based system. If MISRA really is silent about POSIX library functions, then it stands to reason that any functions in the POSIX library should be unrestricted. That would include fork, exec, and popen which are all defined by POSIX, not by the C language standard. Of the three, popen is probably most similar in functionality/interface to the C system function.

That said, you may want to ask yourself why MISRA C restricts the use of the system function and whether or not the same rationale applies to the use of the above three functions as well.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda