Running process in the background

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Running process in the background
# 1  
Old 04-10-2018
Running process in the background

Hi,

I have this simple c program that creates duplicate process with fork():

Code:
#include <sys/types.h>
main()
{
if (fork() == 0)
while(1);
else
while(1);
}

I tried running it in the background

Code:
gcc -o test first.c
test &

And I got this list of running process:

Code:
ps -l
F S   UID    PID   PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
0 S  1000  46202  46194  0  80   0 -  5782 wait   pts/0    00:00:01 bash
0 T  1000  47701  46202  0  80   0 -  1998 signal pts/0    00:00:00 awk
0 T  1000  47702  46202  0  80   0 -  1998 signal pts/0    00:00:00 awk
0 R  1000  54295  46202  0  80   0 -  8370 -      pts/0    00:00:00 ps
[3]   Exit 1                  test

Why can`t I see the PID of the two process (father and son) created with the fork() ?
# 2  
Old 04-10-2018
You can't see the processes because they finished when you issued ps:
Code:
[3]   Exit 1                  test

My c knowledge is maybe a bit rusted, but you keep using the cpu all the time with your infinite loops and may have hit some limitation which caused your processes to abort. Maybe use sleep inside your loops to avoid overusing the cpu?
# 3  
Old 04-10-2018
Quote:
Originally Posted by cero
You can't see the processes because they finished when you issued ps:
Code:
[3]   Exit 1                  test

My c knowledge is maybe a bit rusted, but you keep using the cpu all the time with your infinite loops and may have hit some limitation which caused your processes to abort. Maybe use sleep inside your loops to avoid overusing the cpu?
Thanks,

but it ended up the same way

Last edited by uniran; 04-10-2018 at 11:21 AM..
# 4  
Old 04-11-2018
Code:
ps -el

lists all the processes.
# 5  
Old 04-11-2018
I think the problem is much simpler than you might think. Your choice of name for your code (test) is the name of a shell built-in in most shells and the name of a utility probably located in /bin or /usr/bin on your system and, therefore, likely will be found in your search path before a utility named test located in your current working directory.

You will probably see exactly what you were expecting to see (two copies of your test utility running) if you invoke it with:
Code:
./test &

instead of with:
Code:
test &

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to return from background process and check if it is running or not?

Hi Team, i am executing 3 scripts in background from 1 script and i want to send a message once the script gets completed.these scripts usually takes 1 hr to complete. My sample script is below, Vi abc.sh sh /opt/data/Split_1.sh & sh /opt/data/Split_2.sh & sh /opt/data/Split_3.sh & ... (3 Replies)
Discussion started by: raju2016
3 Replies

2. UNIX for Advanced & Expert Users

Issue with tracking successful completion of Child process running in background

Hello All, I am using Linux. I have two scripts: inner_script.ksh main_wrapper_calling_inner.ksh Below is the code snippet of the main_wrapper_calling_inner.ksh: #!/bin/ksh ppids=() ---> Main array for process ids. fppids=() ---> array to capture failed process ids. pcnt=0 --->... (5 Replies)
Discussion started by: dmukherjee
5 Replies

3. Shell Programming and Scripting

Running Shell Script in the cron, background process

Hi, i was looking for an answer for some trouble im having runing a script in the cron, thing is, that when i run it manually it works just fine. But when cron runs it, it just doenst work. I saw a reply on a similar subject, suggesting that the . .profile worked for you, but im kind of... (9 Replies)
Discussion started by: blacksteel1988
9 Replies

4. Shell Programming and Scripting

command to see process running at background

Hi , I want to see all the background process that are running in unix box machine...please guide me is there any specific command for that..since I am executing some scripts at background..!!:confused: (1 Reply)
Discussion started by: nks342
1 Replies

5. UNIX for Advanced & Expert Users

send a new value to a variable in a running background process

Hi guys, I have a issue with a background process, I need to update the value of a variable in that process which is running at this time and it will be running for at least 2 days. Any idea? I will apreciate your help. regards. Razziel. (2 Replies)
Discussion started by: razziel
2 Replies

6. Shell Programming and Scripting

How to export a variable from a child process running in background to the parent

Hi All, I have a script which calls a child script with a parameter to be run in the background . childscript.ksh $a & Can any one suggest me how do i export a variable from the child script to parent script? Note that the child script is in background If the child script is in... (3 Replies)
Discussion started by: aixjadoo
3 Replies

7. UNIX for Advanced & Expert Users

make a foreground running process to run background without hang up

I've tried this a long time ago and was successful but could not remember how i did it. Tried ctrl+Z and then used bg % could not figure what i did after to keep it no hangup - not sure if used nohup -p pid, can u plz help me out if this can be done. Any help will be appreciated. (12 Replies)
Discussion started by: pharos467
12 Replies

8. Shell Programming and Scripting

How to know the status of process running in background

I have run one shell script in background that contains a endless while loop. I am not able to know the status of that job . Please provide any command to know this. I have already used "ps -aef" , "jobs" to know it , but it didn't work. I am sure the process is running as it is generating a file... (8 Replies)
Discussion started by: sumanta
8 Replies

9. Solaris

how to capture oracle export log while running as background process

I ran the Oracle 9i export command from a terminal to export out a big table using "exp andrew/password file=andrew.dmp log=andrew.log" From the terminal I can see that the export is running as there is some output from the oracle export job. The export job is not complete yet. When i go check... (4 Replies)
Discussion started by: hippo2020
4 Replies

10. UNIX for Dummies Questions & Answers

running process in background

I'm trying to install a solaris 9 patch cluster and when I try to use & to run in background it won't allow me to enter in my sudo password so it fails the install and sudo auth. Does Solaris not have screen like linux? If & will work what am I doing wrong? sudo ./install_cluster -q & is... (3 Replies)
Discussion started by: kingdbag
3 Replies
Login or Register to Ask a Question