Sponsored Content
Full Discussion: Running C program in UNIX
Top Forums Shell Programming and Scripting Running C program in UNIX Post 302798293 by guruprasadpr on Wednesday 24th of April 2013 07:13:50 AM
Old 04-24-2013
You cannot give the source file directly. Compile your C program and get an exe, and then execute the exe from the shell script.

Like:
Compile your C program:
Code:
 
$ cc -o myprog main.c
$ ls myprog
myprog

Code:
 
#!/bin/bash

echo "Run C program"
./myprog
echo "Ran C program"

Guru.
This User Gave Thanks to guruprasadpr For This Post:
 

10 More Discussions You Might Find Interesting

1. Programming

Running a compiled Program

Just getting into the Unix command line programming and am unable to run any program I write. I am using a Makefile and the source is compiling but when I enter the name of the output file I get back: bash: lab01exe.out: command not found I'm sure I am just dooing something simple... (2 Replies)
Discussion started by: Krebsbac
2 Replies

2. Shell Programming and Scripting

Running a program automatically

How can I make a program run automatically at a certain time of day? My problem is I need to make a small backup program that will back up a few files every day? (3 Replies)
Discussion started by: jvadn0
3 Replies

3. Programming

running a c/c++ program in unix

This is not a question, but rather a simple how-to for programmers who are new to the UNIX environment. I too,am new to UNIX. First I developed a few programs on my box and perfected them until they were satisfactory for execution. Problem was however, that once i compiled and all that,... (2 Replies)
Discussion started by: kray
2 Replies

4. UNIX for Dummies Questions & Answers

Running a program

Hi.Iam new to Linux.i got linux 7.0 pro and dont know how to run programs. I want a perl interputer and i know i installed one but how do i run it ??? Also how do i run a C or C++ editor ?and how do i run cron ? (3 Replies)
Discussion started by: perleo
3 Replies

5. UNIX for Dummies Questions & Answers

running dos program from unix server

Hello, My apologies if this sounds like a stupid question...... but is it possible to call a script that is located on a w2k machine from a csh script bing run on a unix server. Many thanks rkap (1 Reply)
Discussion started by: rkap
1 Replies

6. Programming

running a parallel program

hi , i need to run a parallel program . for example; program1 { array=" the second program should called here : program 2" the execution should continue } the 2nd program should recieve an array of information as argument and it should... (4 Replies)
Discussion started by: bankpro
4 Replies

7. UNIX for Dummies Questions & Answers

Running a program (Dynflow)

Lets get some stuff out of the way before the question. I am currently running FreeBSD 7.0 on a VirtualBox virtual machine. I do not know much about Unix or FreeBSD, though I do run linux at home. My boss gave me some files that he says are a unix version of the program Dynflow. The Programs... (0 Replies)
Discussion started by: poet_will
0 Replies

8. Shell Programming and Scripting

Help with Running More than One Program

Folks, I'm really new to scripting and was wondering if you could help me out. I have the following script that I inherited: #!/bin/bash # # Usage # From the agent directory: # ./run-any-agent AgentName # TAC_AGENT_HOME=`pwd` LIB=${TAC_AGENT_HOME}/lib CLASSPATH=.... (17 Replies)
Discussion started by: DTriniWay
17 Replies

9. Shell Programming and Scripting

Running C# program problem

Hi All, How to run c# program using shell script ? (1 Reply)
Discussion started by: srikar.ch
1 Replies

10. UNIX for Advanced & Expert Users

How to keep program running after logout

Hello everyone. I am logged into a computer through ssh. I would like to run a program and have it keep running after I log out without screen (i forgot to run it). For example: ssh server user/comp~$ top & 12021 exit after that: ssh server user/comp~$ (something, maybe shell... (5 Replies)
Discussion started by: lepetal
5 Replies
prof(1) 						      General Commands Manual							   prof(1)

Name
       prof - analyze profile data

Syntax
       prof [ options ] [ prog_name ] [ pcsampling_data_file ...  ]
       prof -pixie [ -note comment_string ] [ options ] [ prog_name [ bbaddrs_file [ bbcounts_file ...	] ] ]

Description
       The  command  analyzes  one or more data files generated by the compiler's execution-profiling system and produces a listing. Prof can also
       combine those data files or produce a feedback file that lets the optimizer take into account the program's runtime behavior during a  sub-
       sequent compilation.  Profiling is a three-step process: first compile the program, then execute it, and finally run to analyze the data.

       The compiler system provides two kinds of profiling:

	    1.	   pc-sampling interrupts the program periodically, recording the value of the program counter.

	    2.	   basic-block counting divides the program into blocks delimited by labels, jump instructions, and branch instructions. It counts
		   the number of times each block executes. This provides more detailed (line by line) information than pc-sampling.

Using Pc-sampling
       To use pc-sampling, compile your program with the option -p (strictly speaking, it is sufficient to use this option only when  linking  the
       program.)  Then	run  the  program, which allocates extra memory to hold the profile data, and (provided the program terminates normally or
       calls records the data in a file at the end of execution.

       The environment variable PROFDIR determines the name of the pc-sampling data file and determines whether pc-sampling takes place:  if it is
       not  set,  the  pc-sampling data file is named mon.out ; if it is set to the empty string, no profiling occurs; if it is set to a non-empty
       string, the file is named string/pid.progname, where pid is the process id of the executing program and progname is the program's name,	as
       it appears in argv[0]. The subdirectory string must already exist.

       After running your program, use to analyze the pc-sampling data file.

       For example:

	    cc -c myprog.c
	    cc -p -o myprog myprog.o
	    myprog		     (generates "mon.out")
	    prof myprog mon.out

       When  you  use  for pc-sampling, the program name defaults to a.out and the pc-sampling data file name defaults to mon.out ; if you specify
       more than one pc-sampling data file, reports the sum of the data.

Using Basic-block Counting
       To use basic-block counting, compile your program without the option -p .  Use to translate your program into a profiling version and  gen-
       erate a file, whose name ends in .Addrs, containing block addresses. Then run the profiling version, which (assuming the program terminates
       normally or calls will generate a file, whose name ends in .Counts, containing block counts.  Then use with the -pixie  option  to  analyze
       the bbaddrs and bbcounts files. Notice that you must tell the name of your original program, not the name of the profiling version.

       For example:

	    cc -c myprog.c
	    cc -o myprog myprog.o
	    pixie -o myprog.pixie myprog       (generates "myprog.Addrs")
	    myprog.pixie		  (generates "myprog.Counts")
	    prof -pixie myprog myprog.Addrs myprog.Counts

       When  you  use  with  the -pixie option, the program name defaults to a.out , the bbaddrs file name defaults to program_name.Addrs, and the
       bbcounts file name defaults to program_name.Counts. If you specify more than one bbcounts file (never specify more than one bbaddrs  file),
       reports	the  sum of the data.  -note comment_string If you use this argument, the comment_string appears near the beginning of the listing
       as a comment.

       Provided you do not use -pixie, processes mon.out files produced by earlier versions of the compiler system using the obsolete -p2  or  -p3
       options.

Options
       For  each  option,  you	need  type only enough of the name to distinguish it from the other options (usually the first character is suffi-
       cient).	Unless otherwise noted, each part of the listing operates only on the set of procedures that results from the combination  of  the
       -exclude and -only options.

       If the options you specify would neither produce a listing nor generate a file, uses -procedures plus -heavy by default.

       -pixie	 Selects pixie mode, as opposed to pc-sampling mode.

       -procedures
		 Reports  time	spent  per  procedure (using data obtained from pc-sampling or basic-block counting; the listing tells which one).
		 For basic-block counting, this option also reports the number of invocations per procedure.

       -heavy	 Reports the most heavily used lines in descending order of use (requires basic-block counting).

       -lines	 Like -heavy , but gives the lines in order of occurrence.

       -invocations
		 For each procedure, reports how many times the procedure was invoked from each of  its  possible  callers  (requires  basic-block
		 counting).  For this listing, the -exclude and -only options apply to callees, but not to callers.

       -zero	 Prints a list of procedures that were never invoked (requires basic-block counting).

       -testcoverage
		 Reports all lines that never executed (requires basic-block counting).

       -feedback filename
		 Produces  a  file  with  information  that the compiler system can use to decide what parts of the program will benefit most from
		 global optimization and what parts will benefit most from in-line procedure substitution (requires basic-block counting). See

       -merge filename
		 Sums the pc-sampling data files (or, in pixie mode, the bbcounts files) and writes the result into a new file with the  specified
		 name. The -only and -exclude options have no effect on the merged data.

       -only procedure_name
		 If  you use one or more -only options, the profile listing includes only the named procedures, rather than the entire program. If
		 any option uses an uppercase O for Only, uses only the named procedures, rather than the entire program, as the base  upon  which
		 it calculates percentages.

       -exclude procedure_name
		 If  you use one or more -exclude options, the profiler omits the specified procedure and its descendents from the listing. If any
		 option uses an uppercase E for Exclude, also omits that procedure from the base upon which it calculates percentages.

       -clock megahertz
		 Alters the appropriate parts of the listing to reflect the clock speed of the CPU. If you do not specify megahertz,  it  defaults
		 to 8.0.

       -quit n	 Truncates  the  -procedures  and  -heavy listings. It can truncate after n lines (if n is an integer), after the first entry that
		 represents less than n percent of the total (if n is followed immediately by a percent character (%)), or  after  enough  entries
		 have been printed to account for n percent of the total (if n is followed immediately by cum%).  For example:
		 -quit 15
		 truncates each part of the listing after 15 lines of text.
		 -quit 15%
		 truncates each part after the first line that represents less than 15 percent of the whole.
		 -quit 15cum%
		 truncates each part after the line that brought the cumulative percentage above 15 percent.

Restrictions
       The command does not yet take into account interactions among floating-point instructions.

Files
       crt0.o	    normal startup code
       mcrt0.o	    startup code for pc-sampling
       libprof1.a   library for pc-sampling
       mon.out	    default pc-sampling data file

See Also
       as(1), cc(1), pixie(1), profil(2), monitor(3)
       Guide to Languages and Programming

								       RISC								   prof(1)
All times are GMT -4. The time now is 08:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy