Re: [Fwd: Re: How to use a shell command in an application?]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



use popen system call. it will give u the flexibility to read the out put.
# man popen

On 5/10/05, Sandeep <sandeep@xxxxxxxxxxxxxxx> wrote:
> 
> 
> 
> 
> ---------- Forwarded message ----------
> From: "Sachin Rane" <sachin.trane@xxxxxxxxx>
> To: "'Sandeep'" <sandeep@xxxxxxxxxxxxxxx>
> Date: Tue, 10 May 2005 11:05:50 -0700
> Subject: RE: How to use a shell command in an application?
> Hi Sandeep,
> 
> Could you forward my reply to 'kernelnewbies@xxxxxxxxxxxx' and  'Yasmine
> Habib'?
> This mail may not reach them because of firewall settings.
> 
> /****************************************************/
> // Below is the example of executing shell command
> // "cat > /proc/iomem" from application
> //
> /****************************************************/
> 
> #include <unistd.h>
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <fcntl.h>
> #include <stdio.h>
> 
> int main(void)
> {
>        int fd_exec;
>        char *const arg_list[]= {
>                "cat",
>                "/proc/iomem",
>                NULL
>        };
>        if(fork() == 0)
>        {
>        /*** Please note below 3 statements can be replaced by the above two
>           statements viz close(1) & open(...) ***/
>                fd_exec = open("/tmp/iomemdump", O_CREAT | O_WRONLY );
>                dup2(fd_exec,1);
>                close(fd_exec);
>                execvp("/bin/cat",arg_list);
>        }
>        printf("Hello\n");
>        return 0;
> }
> 
> Regards,
> Sachin Rane
> 
> -----Original Message-----
> From: kernelnewbies-bounce@xxxxxxxxxxxx
> [mailto:kernelnewbies-bounce@xxxxxxxxxxxx]On Behalf Of Sandeep
> Sent: Monday, May 09, 2005 10:07 PM
> To: Yasmine Habib
> Cc: kernelnewbies@xxxxxxxxxxxx
> Subject: Re: How to use a shell command in an application?
> 
> Yasmine Habib wrote:
> 
> >How can i use a shell command inside a program or application? in
> >other words, i am writing a small scheduler that needs to get the
> >current cpu usage/utliization of a processor at a certain time. using
> >"top", "free", "vmstat" provide me with required information but just
> >as a display when used as a shell command. i need the code to be
> >written inside my scheduler.
> >
> >
> You can try it out with the system( ) call. This will give you the
> flexibility to run any command that u can run in the shell.
> 
> sandeep
> 
> >Thank you
> >
> >--
> >Kernelnewbies: Help each other learn about the Linux kernel.
> >Archive:       http://mail.nl.linux.org/kernelnewbies/
> >FAQ:           http://kernelnewbies.org/faq/
> >
> >
> >
> >
> 
> --
> Kernelnewbies: Help each other learn about the Linux kernel.
> Archive:       http://mail.nl.linux.org/kernelnewbies/
> FAQ:           http://kernelnewbies.org/faq/
> 
> http://www.patni.com
> World-Wide Partnerships. World-Class Solutions.
> _____________________________________________________________________
> 
> This e-mail message may contain proprietary, confidential or legally
> privileged information for the sole use of the person or entity to
> whom this message was originally addressed. Any review, e-transmission
> dissemination or other use of or taking of any action in reliance upon
> this information by persons or entities other than the intended
> recipient is prohibited. If you have received this e-mail in error
> kindly delete  this e-mail from your records. If it appears that this
> mail has been forwarded to you without proper authority, please notify
> us immediately at netadmin@xxxxxxxxx and delete this mail.
> _____________________________________________________________________
> 
> 
> 


-- 
-----------
S K T
-----------

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux