I want to know can I run some compiled C program for example main.exe with option, that make sleep it after program work? Or can I run immediatly second program and using process, which running with main.exe?
I need to calculate memory of process, when I do it in background /proc/[pid]/status and ps aux show me incorrect values, because main.exe works so fast.
Or may be I can exec 2 programs in C using one fork()? Or can make option for execv or execl?
            Asked
            
        
        
            Active
            
        
            Viewed 64 times
        
    -5
            
            
         
    
    
        too honest for this site
        
- 12,050
- 4
- 30
- 52
 
    
    
        Ali S. Veliyev
        
- 53
- 9
- 
                    1`main.exe` on linux? – yizzlez Jul 30 '15 at 13:09
- 
                    C and C++ are **different** languages! Please think about the idea of tagging. – too honest for this site Jul 30 '15 at 13:09
- 
                    @awesomeyi: Why not? Linux is not restricted to a specific filename-suffix :-) – too honest for this site Jul 30 '15 at 13:10
- 
                    @awesomeyi `gcc program.c -o main.exe` i don't see strange thing here – Ali S. Veliyev Jul 30 '15 at 13:10
- 
                    @Olaf my version of `g++` can compile my C program when I change extension of file) – Ali S. Veliyev Jul 30 '15 at 13:12
- 
                    It is, however, uncommon (and ugly). You really should use a more descritive name. – too honest for this site Jul 30 '15 at 13:12
- 
                    Beacuse that is basically gcc. However, these are still different languages. Even the same syntax may have different semantics. If you do not understand this, please read a C and C++ book. – too honest for this site Jul 30 '15 at 13:14
- 
                    I know C and C++, I don't write specialy Visual C++, I see c++ more popular tag than simple c because need quickly useful answers – Ali S. Veliyev Jul 30 '15 at 13:16
- 
                    2@АлиВелиев You're not supposed to do that. I don't tag my R questions Python for quick answers... – yizzlez Jul 30 '15 at 13:17
- 
                    You should add more tags. The more the better, best for completely unrelated topics, so even more people will read your post (and vote to clear and/or downvote). – too honest for this site Jul 30 '15 at 13:20
- 
                    Given how the question is phrased here, this is *neither* c *nor* c++. It could *maybe* apply to both. – Jul 30 '15 at 13:22
- 
                    @FelixPalmen: OP is clearly asking for C and answers can be different (once he clarifies what he actually wants to accomplish) – too honest for this site Jul 30 '15 at 13:24
- 
                    http://stackoverflow.com/questions/131303/how-to-measure-actual-memory-usage-of-an-application-or-process – Jeyaram Jul 30 '15 at 13:25
- 
                    1Other than being mentioned, I can't see anything "C" here. Let's just agree the question is completely unclear. – Jul 30 '15 at 13:25
- 
                    Из-за этих вот кретинов я не могу теперь задавать вопросы... Доебались до хештегов бля и заминусовали всё... – Ali S. Veliyev Jul 20 '17 at 19:33
2 Answers
1
            In Linux, time command can be used to calculate execution time, memory usage, etc
Refer http://linux.die.net/man/1/time
Usage ::
$ time main.exe
 
    
    
        Jeyaram
        
- 9,158
- 7
- 41
- 63
0
            
            
        If you have access to source code of your application just insert code to send signal SIGSTOP to itself at the point you want to measure:
 raise( SIGSTOP );
then you can measure whatever you want and let program go by sending SIGCONT from outside. If you do not have such access you may try to run this process and send signal outside, for example by shell script, but you would need to play with delay:
#!/bin/bash
./main.exe &
sleep 0.1 # this may not work on your distro, you will need to find how to sleep subsecond
kill -SIGSTOP %1
 
    
    
        Slava
        
- 43,454
- 1
- 47
- 90
- 
                    
- 
                    But if I don't have access to source, and have just compiled? sleep 0.1 not works – Ali S. Veliyev Jul 30 '15 at 13:18
- 
                    
- 
                    
- 
                    @АлиВелиев: Unless you like race-conditions, you might want to read about `ptrace()` (where applicable). – EOF Jul 30 '15 at 13:21
- 
                    @АлиВелиев if sleep 01. does not find a way to sleep subsecond, for example here http://unix.stackexchange.com/questions/50722/need-a-loop-to-sleep-for-a-fraction-of-second you may try to kill without any delay. – Slava Jul 30 '15 at 13:22
-